WebSocket-Node icon indicating copy to clipboard operation
WebSocket-Node copied to clipboard

Issue with strange close connections

Open filmen opened this issue 4 years ago • 6 comments

Hello, I've a strange problem to keep a client connected for a long time. Here is the scenario: my node app sends events to real-time dashboard where users are connected by browser via websocket and, sometimes the websocket connection doesn't remain up and the user doesn't receive the new events, expecially when a user is connected from home (ex. works in smartworking). I've tried a lot of things:

  • set false keepalive of module and write a custom new keepalive (with setInterval and setTimeout to handle the websocket connection of every user) that drop connection after 10 seconds if the user's browser doesn't answer at keepalive message;
  • remove my custom keepalive (because doesn't fix the issue), use the keepalive of module and tune the settings to try to keep clients connected with this values: keepalive: true, keepaliveInterval: 20000, keepaliveGracePeriod: 10000, dropConnectionOnKeepaliveTimeout: false, disableNagleAlgorithm: true, fragmentOutgoingMessages: false
  • implemeted a round trip to check latency between my server and the user's browser (for clients that worked in smartworking sometimes are very high, on average 5/6 sec. and sometimes longer than 10 seconds - values ​​are too high in my opinion);
  • the error handler didn't show issue; only with the last modifications (use keepalive module), I see this "Error: read ETIMEDOUT";
  • firewall doens't have rules that blocks traffic on port with the app works;
  • It is possibile that a user VPN increase the latency and so the module drop the connections?

I have tested the code it with lan, wi-fi and 4G tethering and I don't have any problem but my clients, with theirs connections, have this problem also after the use the keepalive module.

What can I do to fix this situation? I'm working in a new version of app with node 14.15.2 and last version of module (1.0.33) but meanwhile I have to fix this issue. Thanks in advice.

Node version: 6.14.4 Module version: 1.0.23 SO: Debian 10

filmen avatar Jan 11 '21 09:01 filmen

I have same issue

Sasha2018RL avatar Jan 15 '21 23:01 Sasha2018RL

Temporary fixed for my case by adding ping method, and if it fails - I using force reconnect

Sasha2018RL avatar Jan 15 '21 23:01 Sasha2018RL

Temporary fixed for my case by adding ping method, and if it fails - I using force reconnect

Hi! Do you use ping/pong function of connection instance (WebSocketConnection) or you have implemented a custom ping/pong?

filmen avatar Jan 18 '21 08:01 filmen

@filmen @Sasha2018RL I stumble upon the same issue, did you solve this? For now, I keep restarting my app every week

madeindra avatar Apr 01 '21 10:04 madeindra

@filmen @Sasha2018RL I stumble upon the same issue, did you solve this? For now, I keep restarting my app every week

I moved to socket io

Sasha2018RL avatar Apr 01 '21 13:04 Sasha2018RL

@Sasha2018RL Can you share your old ping method for temporary fix please?

madeindra avatar Apr 03 '21 01:04 madeindra