Closed berbaba closed 1 year ago
Hello, thanks for the issue.
It appears on my end like we are not closing connections cleanly in certain cases or not responding how the websocket library expects PINGs to be handled. I will have to look into why PING
keep alive messages are timing out.
You should be fine to disable the ping_interval
in the meantime.
It is possible we are closing the connection on our end for a variety of reasons (clearly not cleanly as you have demonstrated which we should fix). The two most likely reasons are you are not reading the messages fast enough. We close connections with full write buffers ( tcp buffer + 2 mb additional write buffer ) to reduce noisy neighbour issues and prevent slow clients from affecting other users. We also throttle subscription updates to 1/sec and close connections after sending an error message if they exceed it.
Thanks for opening the issue. I will try and reproduce this myself in the coming days.
I looked into our logs and in your case it does not appear to be us closing the connection. So you can ignore the advice about slow clients or throttling.
What appears to be happening is as follows:
PING
requests we are not providing a response fast enoughAt the moment why we are not responding to PINGs in a timely manner is not known but it will be looked into.
Closing due to inactivity.
Thanks for your help in advance. When running the Python example, after some undetermined time (sometimes 1h, sometimes 45 min...) it crashes. The error can be also reproduced just manually disconnecting and waiting for 50 seconds or so. The error is the following:
Looking for solutions I stumbled upon this one that suggests setting the ping interval to None (I'm guessing the value is by default set by the server to those 50s) in:
async with websockets.connect("wss://stream.aisstream.io/v0/stream", ping_interval=None) as websocket:
This seems to work, loosing connection just pauses the stream (I guess all messages until the connection is restablished are lost) and then resumes without a problem. But I don't know if there's a catch I don't know about and if this solution should be used (My goal is to keep the connection up as long as possible and reconnect automatically if the connection is lost). If it's fine, could be added to the code. Thank you.