realtime-py
realtime-py copied to clipboard
Socket disconnect after a while
Hi!
I am facing an issue both in local (Mac OS Sonoma 14.2) and deployed on render.com.
Basically after a while the socket close without receiving further updates and I get this error:
2024-01-26 04:04:08,363:ERROR - Connection with the server closed. Traceback (most recent call last): File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 959, in transfer_data message = await self.read_message() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 1029, in read_message frame = await self.read_data_frame(max_size=self.max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 1104, in read_data_frame frame = await self.read_frame(max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 1161, in read_frame frame = await Frame.read( ^^^^^^^^^^^^^^^^^ File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/framing.py", line 68, in read data = await reader(2) ^^^^^^^^^^^^^^^ File "/opt/render/project/python/Python-3.11.0/lib/python3.11/asyncio/streams.py", line 726, in readexactly raise exceptions.IncompleteReadError(incomplete, n) asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 2 expected bytes The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/opt/render/project/src/.venv/lib/python3.11/site-packages/realtime/connection.py", line 76, in _listen msg = await self.ws_connection.recv() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 568, in recv await self.ensure_open() File "/opt/render/project/src/.venv/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 930, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: no close frame received or sent
To Reproduce
- Launch the server with python main.py
- Wait a while without receiving updates on the socket
Expected behavior
The socket should't disconnect.
Additional context
This is my current python code
if __name__ == "__main__":
URL = f"wss://{os.getenv('SUPABASE_ID')}.supabase.co/realtime/v1/websocket?apikey={os.getenv('SUPABASE_SERVICE_KEY')}&vsn=1.0.0"
s = Socket(URL)
s.connect()
channel_1 = s.set_channel("realtime:public:todos")
channel_1.join().on("INSERT", lambda msg: asyncio.ensure_future(callback(msg)))
s.listen()
Having the same issue -- any updates or workarounds on this?
Same issue with me.