Client timeouts

2,500 views
Skip to first unread message

murz

unread,
Oct 23, 2011, 12:03:41 AM10/23/11
to Socket.IO
Hi,

I'm writing my first Node.js/Socket.IO app, and I noticed that my
clients are consistently disconnecting after 25 seconds. Then in the
wiki I found that there is a 'close timeout' that defaults to 25
seconds.

So I'm a little confused - why is there a timeout like that? Does my
client have to keep pinging the server every 24 seconds to keep the
connection alive? My app is a game where the first user may have to
wait > 25 seconds before more users join and activity starts coming
from the server so I need to find a way around this.

Any tips you have are much appreciated, thanks!

Jason Chen

unread,
Oct 23, 2011, 9:25:02 PM10/23/11
to sock...@googlegroups.com
The close timeout is how long a connection has to reconnect after disconnecting so it shouldn't be causing disconnections: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO. Try varying this value to see if your clients disconnect after this new value? Socketio does use heartbeats to make sure clients are still there but that's all done under the hood and you in general should not have to worry about this (though imo the default values should be much larger).

murz

unread,
Oct 23, 2011, 11:35:12 PM10/23/11
to Socket.IO
I tried changing 'heartbeat timeout', 'heartbeat interval', and 'close
timeout' but my client still disconnects after 25 seconds.

It's only happening for Chrome using web sockets, the clients in FF
using xhr polling stay alive.

WHen it disconnects I see this in the server side output:

debug - clearing poll timeout
info - transport end
debug - set close timeout for client 9273883436715195
debug - cleared close timeout for client 9273883436715195
undefined
debug - discarding transport

murz

unread,
Oct 24, 2011, 1:17:37 AM10/24/11
to Socket.IO
Actually, when I change 'close timeout' to 50 seconds my web socket
client disconnects every 50 seconds, so I assume that has something to
do with it.

What exactly is the significance of this 'close timeout' field? I
don't really understand the description "The timeout for the client,
when it closes the connection it still X amounts of seconds to do re
open of the connection. This value is sent to the client after a
successful handshake."

And any tips for how to keep my client alive despite this close
timeout?

On Oct 23, 6:25 pm, Jason Chen <jhch...@gmail.com> wrote:

Jason Chen

unread,
Oct 24, 2011, 11:18:38 PM10/24/11
to sock...@googlegroups.com
I'm no expert on this topic but I interpreted close timeout as being the amount of time after a disconnect, that the client has to reconnect and still get the same connection to resume. After that time, the connection is assumed to be dead and may be garbage collected.

So it may be the case there's some confounding events going on in that the close timeout is not causing your disconnects; rather the connection is dying immediately but it's only reported after close timeout expires because that's how long it waits around for the client to reconnect before giving up. This would explain why it's always 25 seconds or whatever your close timeout value is before you get the disconnect.

Here's what I see in a normally operating connection:

   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 6532049221552199402
   debug - setting request GET /socket.io/1/websocket/6532049221552199402
   debug - set heartbeat interval for client 6532049221552199402
   debug - client authorized for 
   debug - websocket writing 1::
Got packet from 6532049221552199402    <-- Here the server receives a packet from my client (I'm logging this, not socketio)
   debug - sending data ack packet
   debug - websocket writing 6:::1+[{ //What my server responds with }]

   info  - transport end     <-- My client now navigates away which tells the sever to close
   debug - set close timeout for client 6532049221552199402
   debug - cleared close timeout for client 6532049221552199402
   debug - cleared heartbeat interval for client 6532049221552199402
   debug - discarding transport

The "undefined" being printed in your log is troubling, and it seems that the "cleared hearbeat interval..." log is missing so maybe something is wrong with your heartbeat interval?

You might have already done this but the example socketio app works and would be a good base test to make sure everything is set up correctly without having to worry about the code.

Best,
Jason Chen

murz

unread,
Oct 23, 2011, 11:58:25 PM10/23/11
to Socket.IO
I tried changing 'heartbeat interval', 'heartbeat timeout', and 'close
timeout', but my clients are still disconnecting after 25 seconds. It
only happens to my clients running Chrome/Websockets, the FF/xhr-
polling ones stay connected.

When they disconnect I see this in the server output:

debug - clearing poll timeout
info - transport end
debug - set close timeout for client 9273883436715195
debug - cleared close timeout for client 9273883436715195
undefined
debug - discarding transport

On Oct 23, 6:25 pm, Jason Chen <jhch...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages