websocket random startup issue

Hi,

We’re seeing a rather unpredictable behaviour/pattern at startup. In summary;

When we start our binance gateway, we establish a connection to

‘wss://fstream.binance.com/stream’

The connection is established and we then go into our connection management loop whereby if we hear nothing from binance for a minute, we enter a disconnect/reconnect loop until we get reconnected and wait for data again (1 minute).

Now the problem ONLY happens (randomly) at startup. Once we are connected everything works fine. The problem isnt consistently repeatable. The only option availailable is to repeatedly restart the gateway until the boot cycle (connect + receive data in less than a minute) completes ok. This is production code and has been working for a long time.

Can anybody help diagnosing or think of anything that may be the root cause? I see nothing wrong but am not sure. I presume as part of the gateway → websocket → binance communications, we need to be in some sort of a ping-pong loop (keepalive). Thats correct, yes?

Thanks

Graham

Hi. It’s hard to tell what’s the reason immediately. You need to do more troubleshooting to filter down the possibilities. Some ideas:

  • Make sure you’re debug logging your websocket connection to know what point in time it disconnects and see if you can capture some message detailing the reason for disconnection.
  • It might not related with the websocket itself but maybe you’re having some network problems (VPN, proxy, firewall, …) that could interfere with the connection.
  • The websocket library you’re using is updated and without report of similar issues.
  • Make sure you’re following all the webscket rules declared in this page Binance API Documentation.

I bet you have a blocking code! Check your code, add some console logs before each function and you will find which one blocks the code.