socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Client disconnects+reconnects repeatedly every 15 seconds

Open pearjoint opened this issue 15 years ago • 13 comments

Summary:

Using the master branch, downloaded about 19 hours ago -- a simpleton vanilla setup with the Socket.IO client script connecting to the Socket.IO-node server side and then both parties simply sitting idle. Consistently and repeatedly, ie. all the time across various tests and restarts does the connection get lost (rather than kept-alive as it should with an idle server and one idle client) every 15 seconds or so.

Details:

Client side uses the client script served by Socket.IO-node.

There is no communication between server side and client side yet after the initial handshake (where my server side sends the client its Socket.IO-generated sessionid).

So this is pretty much a vanilla setup; the server side sits very still and is definitely not "too busy". Client-server handshake work fine. But after that, BOTH Chrome+Websocket AND Firefox+Flashsocket experience regular disconnects from the server side, seemingly every 15 seconds.

My otherwise empty client HTML test page now logs all Socket.IO events, newest on top / oldest on bottom. Here is one, in the timings only the seconds matter and one can see a disconnect/reconnect every 15 seconds if you inspect this from bottom to top:

"2011-05-24T14:56:30.399Z" — Message: [6954755357000977] "2011-05-24T14:56:30.399Z" — Reconnected: websocket after 1 attempts "2011-05-24T14:56:30.398Z" — Connected "2011-05-24T14:56:30.389Z" — Reconnecting in 1000 ms, 1 attempts "2011-05-24T14:56:30.389Z" — Connecting [websocket] "2011-05-24T14:56:29.888Z" — Disconnected "2011-05-24T14:56:14.887Z" — Message: [27254397980868816] "2011-05-24T14:56:14.886Z" — Reconnected: websocket after 1 attempts "2011-05-24T14:56:14.886Z" — Connected "2011-05-24T14:56:14.876Z" — Reconnecting in 1000 ms, 1 attempts "2011-05-24T14:56:14.876Z" — Connecting [websocket] "2011-05-24T14:56:14.375Z" — Disconnected "2011-05-24T14:55:59.375Z" — Message: [4725480892229825] "2011-05-24T14:55:59.374Z" — Reconnected: websocket after 1 attempts "2011-05-24T14:55:59.374Z" — Connected "2011-05-24T14:55:59.371Z" — Reconnecting in 1000 ms, 1 attempts "2011-05-24T14:55:59.371Z" — Connecting [websocket] "2011-05-24T14:55:58.869Z" — Disconnected "2011-05-24T14:55:43.869Z" — Message: [2773561452049762] "2011-05-24T14:55:43.868Z" — Reconnected: websocket after 1 attempts "2011-05-24T14:55:43.868Z" — Connected "2011-05-24T14:55:43.865Z" — Reconnecting in 1000 ms, 1 attempts "2011-05-24T14:55:43.864Z" — Connecting [websocket] "2011-05-24T14:55:43.363Z" — Disconnected "2011-05-24T14:55:28.362Z" — Message: [6230101911351085] "2011-05-24T14:55:28.362Z" — Connected "2011-05-24T14:55:28.357Z" — Connecting [websocket]

I have not customized any timeouts that maybe can (or should?) be customized, except { connectTimeout: 5000 } but I don't think this matters here. I understand the client sends heartbeats regularly... how often by default? Only every 1 or 2 minutes, right? Why would the server side disconnect my clients?

pearjoint avatar May 24 '11 15:05 pearjoint

Am I seriously the only one seeing this?

pearjoint avatar Jun 02 '11 18:06 pearjoint

Are you using a reverse proxy? Have you tried other servers?

vincentwoo avatar Jun 02 '11 23:06 vincentwoo

No proxy / reverse proxy in use -- a vanilla NodeJS http server running on a normal local Ubuntu 10.10 64bit developer machine.

pearjoint avatar Jun 03 '11 14:06 pearjoint

I'm experiencing this as well. Got my app on a Linode today, and have been trying to figure out what is causing this ever since. I assume I'm doing something wrong, but have no idea what it is. Any luck with it?

5HT2A avatar Jun 10 '11 00:06 5HT2A

Still at a loss on this issue.

pearjoint avatar Jun 10 '11 19:06 pearjoint

I am also on Linode and experiencing disconnect/reconnect cycles between nodejs on the linode and the web client in Google Chrome. Have you ever noticed how your Linode will hang up your plain-old-notnodejs ssh sessions after a few minutes of inactivity? At least mine do. Could this be related?

DrPaulBrewer avatar Jun 12 '11 07:06 DrPaulBrewer

OK. Nodejs/socket.io NOT disconnecting on localhost at home (after 10+ min). The app is disconnecting/reconnecting when hosted on a linode VPS (after just a few min).

With regard to Linode VPS hosting, there are reports of altered TCPKeepAlive and ClientAliveInterval settings to keep the ssh sessions from closing out after a few minutes.

For more on ssh see http://forum.linode.com/archive/o_t/t_4793/keeping_an_ssh_session_to_my_linode_open.html

I wonder if there are similar tweaks that can be applied to socket.io's internals in node.js ...?

DrPaulBrewer avatar Jun 12 '11 07:06 DrPaulBrewer

Quite a bit of general linux info on TCP Keepalive at http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html

DrPaulBrewer avatar Jun 12 '11 08:06 DrPaulBrewer

UPDATE --- This did not eliminate the disconnection problem. Hard to say whether it helped or not till I see more data. --

Hmm... the info in that last link seemed to help quite a bit, so far. I am using these settings sudo sysctl -w
net.ipv4.tcp_keepalive_time=120
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=10

Could someone else verify that this helps, hurts, or does nothing?

DrPaulBrewer avatar Jun 12 '11 08:06 DrPaulBrewer

I have set ClientAliveInterval to 10 in my linode, and works well, however In my opinion it could be a problem with proxies/firewall/NAT.

Have you tried to enable ServerAliveInterval in the client's ssh_config file? (Only to see if connection always break down )

 # nano or vi /etc/ssh/ssh_config

Append or modify values: (45 secs)

 ServerAliveInterval 15 
 ServerAliveCountMax 3

or

 ssh -o ServerAliveInterval=20 user@host

rootslab avatar Jun 12 '11 11:06 rootslab

And I think that the ultimate test is to try to connect from another machine ( outside your network ;) and see what happens

rootslab avatar Jun 12 '11 11:06 rootslab

Many thanks for your input, but unfortunately none of your suggestions appear to be doing anything for me :(

The issue only exist for me when running an app on Linode, too. No problem running locally. However, Dr. Brewer, I'm not sure that we're dealing with the same issue here, since in my case the disconnect/reconnect nonsense happens every 15-20 seconds or so, whereas you speak of a few minutes. I also noticed, upon further inspection, that the issue only occurs when there are two clients or more connected to the server. A single client can stay connected indefinitely, but once that second client connects, you can count to 15 and the shit hits the fan. Can you make anything of all this?

5HT2A avatar Jun 12 '11 20:06 5HT2A

With Firefox 3.6.18, Node v0.4.8, Socket.io v0.7.9 under Linux Mint on XHR it keeps disconnecting/reconnecting also to me, since I updated the code to v0.7

Fabryz avatar Aug 14 '11 16:08 Fabryz