Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io delay in firing the "disconnect" event?

I have a socket.io client connected to a node.js server. If I kill node.js at the command line, the client immediately freezes (i.e., communication stops), but there is a ~20 second delay before the "disconnect" event is fired. Is this behavior by design? Is there a configuration option to reduce the delay in firing the disconnect event?

It appears that this behavior changed in a relatively recent (last 6 months) update of socket.io. Before the reconnect functionality was built in to socket.io itself, I implemented my own reconnect logic using a "disconnect" event handler and at that time the "disconnect" event fired almost instantly when server communication halted.

like image 396
Scott Brown Avatar asked Nov 04 '22 15:11

Scott Brown


1 Answers

I think this is likely a design pattern. The client may be presuming the server is 'temporarily' unreachable (network trafic etc) and essentially will keep trying to reach it... until the client timeout kicks in.

I send a disconnect (socket.disconnect()) to the server directly from the client, and I don't get this issue.

like image 145
fullstacklife Avatar answered Nov 09 '22 16:11

fullstacklife