supabase / realtime-py

A Python Client for Phoenix Channels
MIT License
134 stars 55 forks source link

Handle socket errors gracefully #30

Open Aergonus opened 2 years ago

Aergonus commented 2 years ago

For a long running realtime subscription, I find that it breaks randomly after a few hours. I would expect this to gracefully reconnect. This using simple https://github.com/supabase-community/realtime-py#sample-usage-with-supabase

2022-02-03 09:37:25,734:ERROR - Connection closed
Traceback (most recent call last):
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 750, in transfer_data
    message = await self.read_message()
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 819, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 895, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 975, in read_frame
    extensions=self.extensions,
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/framing.py", line 55, in read
    data = await reader(2)
  File "/usr/lib/python3.7/asyncio/streams.py", line 679, in readexactly
    await self._wait_for_data('readexactly')
  File "/usr/lib/python3.7/asyncio/streams.py", line 473, in _wait_for_data
    await self._waiter
  File "/usr/lib/python3.7/asyncio/selector_events.py", line 801, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/me/.local/lib/python3.7/site-packages/realtime/connection.py", line 65, in _listen
    msg = await self.ws_connection.recv()
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 421, in recv
    await self.ensure_open()
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 726, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
2022-02-03 09:37:29,153:ERROR - Connection with server closed
Traceback (most recent call last):
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 750, in transfer_data
    message = await self.read_message()
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 819, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 895, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 975, in read_frame
    extensions=self.extensions,
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/framing.py", line 55, in read
    data = await reader(2)
  File "/usr/lib/python3.7/asyncio/streams.py", line 679, in readexactly
    await self._wait_for_data('readexactly')
  File "/usr/lib/python3.7/asyncio/streams.py", line 473, in _wait_for_data
    await self._waiter
  File "/usr/lib/python3.7/asyncio/selector_events.py", line 801, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/me/.local/lib/python3.7/site-packages/realtime/connection.py", line 110, in _keep_alive
    await self.ws_connection.send(json.dumps(data))
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 471, in send
    await self.ensure_open()
  File "/home/me/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 726, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 365 days with no activity.