python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.06k stars 505 forks source link

websocket connection is closing after some time unexpectedly #1433

Closed fti-ravhad closed 4 months ago

fti-ravhad commented 5 months ago

I am using webrtc to live stream media , after some time ice-candidates sending and receiving the connection is closed with below exceptions. Screenshot from 2024-01-18 11-17-17 The connection works for keepalive_timeout time only, after that it closes . What are the reasons behind this exceptions

Python version : 3.10.12 websockets version : 12

Kakcalu13 commented 4 months ago

I have the exact same issue as this.

What is the solution?

aaugustin commented 4 months ago

~https://websockets.readthedocs.io/en/stable/project/contributing.html#cryptocurrency-users~

~(Also -- https://websockets.readthedocs.io/en/stable/faq/client.html#how-do-i-force-the-ip-address-that-the-client-connects-to)~

Kakcalu13 commented 4 months ago

https://websockets.readthedocs.io/en/stable/project/contributing.html#cryptocurrency-users

im not crypto user nor crypto developer :sob: I use ws to communicate with robots

(Also -- https://websockets.readthedocs.io/en/stable/faq/client.html#how-do-i-force-the-ip-address-that-the-client-connects-to)

Thanks! This is pretty much what I have. I called it the temporary bandaid but turn out this is the official solution. Deeply thank you for your time!

aaugustin commented 4 months ago

Oops, sorry — that answer was meant for another issue, namely #1447 — my mistake 🙏

Kakcalu13 commented 4 months ago

That's ok!

You can close this since your doc has the answer already. This answered the main of this issue as well

aaugustin commented 4 months ago

The stack trace shows that the other side in closing the websocket connection normally. That's what received 1000 (OK); then sent 1000 (OK) means. 1000 is the normal close code.

aaugustin commented 4 months ago

I'm glad you could figure it out with the FAQ anyway!

fti-ravhad commented 4 months ago

just add asyncio.TimeoutError .. instead of TimeoutError . This worked for me..