eventsource icon indicating copy to clipboard operation
eventsource copied to clipboard

Detect when connection get lost under abnormal circumstances?

Open qlands opened this issue 6 years ago • 5 comments

I am testing your example ./example/sse-server.js and all works fine under normal circumstances. For example calling curl http://192.168.0.20:8080/sse will start the events (new connection). Cancelling curl (Ctrl +c) will cancel the events (lost connection)

But the "res.on('close'...." does not work when the connection has been lost under abnormal circumstances for example when I switch off the computer (very simple to test with VirtualBox).

Is there any way on detecting this or this is a issue with SSE?

qlands avatar Mar 17 '19 17:03 qlands

A keep-alive or heartbeat would be required to detect this.

If you control both sides you can implement it yourself outside this library.
Server (send heartbeat every x seconds) -> Client (if hearbeat isn't seen in x, force reconnect)

Tungsten78 avatar Aug 20 '19 21:08 Tungsten78

Can we close this?

aslakhellesoy avatar Aug 20 '19 23:08 aslakhellesoy

@Tungsten78 the problem is on the server side because if the client goes dead (power off) the server does not get any disconnect message. It just continue sending messages to the void... I don't know if this is an implementation issue or a protocol issue.

qlands avatar Aug 21 '19 17:08 qlands

@qlands - I didn't catch you were reporting against the example server. My bad.

Writing to an abnormally interrupted socket should always trigger an exception. Very odd what you're seeing. I cannot speak to the example implementation itself.

Tungsten78 avatar Aug 21 '19 17:08 Tungsten78

Yes the issue happens with the example. If I run the server in Linux machine and the client in another Linux using VirtualBox and I switch off the VirtualBox abruptly the server will send messages to a void because it cannot detect that the client has gone.

qlands avatar Aug 22 '19 02:08 qlands