Detect when connection get lost under abnormal circumstances?
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?
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)
Can we close this?
@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 - 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.
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.