supabase / realtime-py

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

Socket disconnect after a while #85

Open Sapessii opened 10 months ago

Sapessii commented 10 months ago

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

  1. Launch the server with python main.py
  2. 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()
chrisgoddard commented 7 months ago

Having the same issue -- any updates or workarounds on this?

loner233 commented 3 months ago

Same issue with me.

yorickvanzweeden commented 2 months ago

I think it comes down to:

However, the auto_reconnect does not seem work properly for me and ignores new events after reconnect. I fixed that behavior in an opinionated fork. This fork does have breaking changes

jackyliang commented 1 week ago

I have the same issue. This library is unusable unfortunately.