Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to set a high close timeout on socket.io?

I have a web application where the user needs to be constantly connected. By default, socket.io will disconnect the connection after 60 seconds. I have 'reconnection' turned on though, so it is essentially closing and reopening the connection every minute. This can cause issues with feeds/notifications to my connected clients. Would it be safe to set this timeout to lets say, 10 minutes, or possibly higher? Is there a reason it is so low right now?

like image 244
Ari Avatar asked Feb 16 '13 20:02

Ari


2 Answers

My guess is that you may be misinterpreting the 'close timeout' configuration. It does not cause the connection to be closed after 60 seconds. (Heartbeats would be pointless if clients constantly reconnected).

If a client disconnects, close timeout is the amount of time the server will wait before releasing resources associated with that connection. Essentially, this allows clients with intermittent connectivity issues to attempt to reconnect before the server has forgotten about them. Setting close timeout to ten minutes is probably a bad idea since it will tie up server resources.

If your clients are, in fact, disconnecting every 60 seconds, then, like samjm said, something else is wrong.

like image 51
Bret Copeland Avatar answered Nov 15 '22 21:11

Bret Copeland


I don't believe your socket should disconnect after 60 seconds. I would investigate why that is actually happening. After handshaking correctly the socket should heartbeat and stay open indefinitely (barring network issues out of your control) until either the client or the server closes the connection, that is definitely my experience.

The fact that your connection is actually closing sounds like it may not be handshaking correctly, or heartbeats are not being received.

like image 30
samjm Avatar answered Nov 15 '22 19:11

samjm