1006 connection closed code but stream never restarts

I use to receive this error alot and it went away but it happened again this morning:

WARNING [stream.py:224] websocket error, restarting connection: code = 1006 (connection closed abnormally [internal]), no reason

However, the connection just never gets restarted. Has anyone else come across this and have any resolutions for it?

Happened again today,

Apr 27 09:55:47 2021-04-27:13:55:47,550 WARNING [stream.py:338] websocket error, restarting connection: code = 1006 (connection closed abnormally [internal]), no reason

Apr 27 09:55:47 2021-04-27:13:55:47,550 WARNING [stream.py:224] websocket error, restarting connection: code = 1006 (connection closed abnormally [internal]), no reason

Anyone ideas?

There is a good article here on websockets which may be of help. Maybe try looking there for ideas on how to trouble shoot.

Hey @Dan_Whitnable_Alpaca ,

Thanks for the article. Just out of curiosity, shouldn’t the web socket reconnect automatically though?

I don’t see anywhere that the subscribed items (ie the trades, quotes, and/or bars) are stored. Therefore, I don’t think when a connection is restored that the subscriptions are automatically restored. One would need to re-subscribe. That may be the issue? I could be way off here. Perhaps someone from the community could verify that.

Thanks as always @Dan_Whitnable_Alpaca I’ll see what I can do ab out reconnection and re-subscribing.

Hi @FIRMCEO, I have the same problem but I’m looking for a proper solution (rather than constant reconnections) From digging a little I found this:

Unfortunately the Stream class doesn’t extend it’s websocket [_ws] field publicly, so there’s no option to add a ping_interval unless changing the API. From DataStream/TradingStream class:

# DataStream
self._ws = await websockets.connect(
            self._endpoint,
            extra_headers={'Content-Type': 'application/msgpack'})

#TradingStream
self._ws = await websockets.connect(self._endpoint)

It doesn’t seem too hard to add it here. If this works for you, I can suggest an edit to the python API regarding this.

1 Like