One potential reason for Websocket abnormal disconnection

Recently we notice that some VPN service providers may disconnect the websocket connection, that can be very hard to debug for client.

It’s quite common to see API users subscribe to websocket server through a VPN. However some VPN providers may disconnect the connection when seeing it’s in idle status.

Binance websocket service is very stable and the server maintain a connection at lest 24hours. So if clients connected to Binance websocket server, but repeatedly see disconnection in a short time. Please check:

  • If the client connected with a VPN
    • disconnect the VPN and see it’s more stable
    • change to a different VPN
    • subscribe a activate market data stream, make sure there is data pushed from server, and see if it improve the connection stability

I could see how that makes sense, but personally speaking, my service is not behind a VPN, but still has its websocket closed abnormally.

For me it has not happened for a while now, but I often see it happening once the markets start moving more than days like this.

1 Like

Thanks for your feedback. For your case, is it possible that too much streams subscribed from the connection, if server is trying push too many data and client is reading not fast enough, it will lead to an unstable connection.

i feel the same too, when ever the market having movement, for sure binance will have error, expecially keep log you out. it is really not stable the connection.

I only have three streams open: trade stream (on only one pair in this case), ticker (on all usdt pairs) and userdata. I don’t think that should generate too much of a load. The applications are also nowhere near their load limits.

“A connection that goes beyond the limit will be disconnected”, how will such a disconnect, or any other wanted disconnect from binance look like? Will it look different from other disconnects?

I’m currently unable to subscribe to all existing books at once, although I already only allow 250 pairs per connection. (currently using the @depth20@100ms book stream) Up to an amount of ~300 pairs in total, everything works fine. But eg. with 500 pairs, I get the first disconnect after 20-60 seconds.
I noticed that the network traffic might be too high for my slow internet_connection, it is always “downloading” at maximum speed for 500 pairs, so there might be more messages sent than my internet can handle. Could this be a reason? (Guess this also depends on the webwocket implementation I use…)

edit:
I switched to @depth20@1000ms with 500 pairs, which only consumes half of my internetspeed, and now it seems to work fine. So I think it was indeed the internetspeed…

@Serpens66

According to my experience your 300 subscriptions is a limit of your internet connection or your cpu.

1 Like

Sorry to revive this thread, but I’m still experiencing issues with websockets sometimes. As you can see from the logs below, multiple different bots (running on a different server each, completely independently) need to reconnect to streams at the exact same time. After these logs, they managed to reconnect, but it’s still odd.