Websocket closes unexpectedly with error 1006

I am having issues with futures websocket where I randomly get 1006 error. Some days it works perfectly fine but some days it throws this error every 10 minutes or so.

I’m developing on nodejs and used ws package in order to connect the websocket. I used “wss://fstream.binance.com” as base url. Only thing I subscribed is @bookTicker and used listen key to get access to user data streams.

I am confident that I handled ping correctly and other than that, I only send listenKey update request and that happens every 50 minutes or so.

Is there anyone who found a fix for this or have an explanation why it keeps throwing this error ?

Thanks.

From my experience the error 1006 occurs when the connection on the client side is abruptly closed either because you closed the connection using the close method of the websocket or also because the internet connection is cut in this case I have noticed that the websocket closes in Automatic after 8 minutes, I have not noticed other cases I have thrown the error 1006 although I have had occasions when the websocket stops working without triggering the close event and therefore I am left without knowing the reason for the closure which still It is an unknown for me why this situation occurs

I am having the exact same issue. I triple checked all possibilities whether I am closing it myself, but I don’t. Yet it still closes with code 1006. Some days this is happening very frequently, other days it is hardly happening at all.

I only use the close method in a callback for error event, and I am pretty sure my connection is solid. It doesn’t go silent for 8 minutes than close. It closes when it was working just fine so I don’t think it is a connection issue either. I don’t know what is causing the issue but it would be nice if binance support look into this and at least provide some kind of explanation so that we can fix this.

I’m having the same problem, my connection is fine, I have other websocket connections that work perfectly, if you managed to fix this error, could you help me

I tested out, that it very depends from cpu, network and amount of subscriptions:

Hello i have an error when i use: wscat -c wss://stream.binance.com:9443/ws/ethusdt@kline_5
its connecting but i dont get any data, in my terminal? if i do the @aggTrade i get data back but nothing via @kline. why does this happen.

@Crypticcube wrong stream name, ethusdt@kline_5m

1 Like

@dino
Thanks bro. (just missing the M)

Hello, in my experience working with the Binance web-socket “API” the issue with disconnects stems from the ping/pong handling.

Particularly user-stream web-socket connection applications would just stop receiving data for no apparent reason. The fix was to send a ping frame on a timer basis rather than wait for Binance’s server to send its ping frame to my application.

I guess without sending pings, you cant define a ping_timeout which is the way to detect dead socket connections…

I had this issue.
The problem was the name of the stream

"wss://stream.binance.com:9443/ws/#{name}"

The variable name had a utf-8 char beyond the 7 bits

Hope this can be usefull.