Suddenly getting a lot of 1008 errors

My Node.js server subscribes to your WebSocket server using the ‘ws’ module. The subscriptions are working fine, but suddenly I see a big increase in getting 1008 errors. My client is configured so that it automatically reconnects when that happens.

My server works well for 2 or 3 days and then once this starts happening, the 1008 errors never go away and my client keeps trying to reconnect (with some backoff), but it never gets resolved.

This happens every couple of days, the last occurrence was November 3, around 0:38 UTC. It starts with some broken connections with the error code 1001, followed by an endless amount of 1008s…

According to this error description document it just means that connections are broken and the server is busy, but why does the server then never recover from being busy until I restart my server? Is this a way of getting IP blocked maybe or am I not doing something I should be doing?

Do you see "code": -1008 in JSON error description? Or is that 1008 close code of the WebSocket protocol? Those are different error codes.

WebSocket’s 1008 is for “policy violation”. Most likely reason for that is sending an invalid request, sending requests too rapidly, or failure to respond to the server’s ping. I’d suggest you add more logging for everything and see if anything happens immediately before the disconnection that might trigger it.

WebSocket’a 1001 code is “server going away”. This one is normal, when the server is shutting down and closes the connection you are expected to reconnect. Binance regularly shuts down connections every 1 to 3 days. The connection is guaranteed to survive for 24 hours (as per documentation), after that it may be closed. It is recommended that you reconnect before that time elapses to minimize unexpected disruptions.

Hi @ilammy thanks for the answer! That seems to be it.

I guess my server does have some rate limiting going but only the first time I connect. The reconnection after getting the 1001 errors is automatically done by ccxt library from what I can tell and there is not enough rate limiting, so probably that’s why I’m getting this.

Just to cross-reference, this is what I’m talking about BinanceUs - rate limits issue in websocket subscriptions · Issue #23525 · ccxt/ccxt · GitHub

I’ll keep you updated here in case there are more questions, but we seem to be close to the issue now.