Tuesday, February 27, 2018

Websocket backend client connection stops receiving stream updates after a while

Leave a Comment

I'm using nodejs's socket.io-client to get a stream of data from a remote websocket server. After a while, I simply stop receiving data from the remote server. There are no errors, or close events. The data simply stops arriving.

What's interesting is that the time before I stop receiving data varies with the specs of the host system.

For instance, on my laptop, which is a 4-core i7 with 16GB memory, it can run overnight (about 8-9 hours) before I stop receiving data. On a small AWS EC2 server, I stop receiving data within 10 minutes.

If I force a reconnect to the remote server, the data starts coming in and will stop receiving after a while again. My current workaround to the issue is to simply reconnect to the remote server every 10 minutes.

I initially thought this was a bug with the remote server I was connecting to, so I switched my data provider. But I am still seeing the issue.

The memory, cpu and file descriptor usage of the nodejs process is nominal. The strace doesn't show anything interesting. I need some ideas on how I can debug this.

Please be reminded that I'm not connecting to the websocket server from the browser, I'm connecting to it from a nodejs script.

1 Answers

Answers 1

If you set the DEBUG environment variable to '*', you will be able to see a lot more information that is happening under the hood (things like ping/pong, disconnects, reconnects, events, etc). This should help narrow down where the issue lies. If that shows too much information, you could also try setting the DEBUG environment variable to 'socket*,engine*'.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment