supabase / realtime-py

A Python Client for Phoenix Channels
MIT License
127 stars 51 forks source link

Calling `Socket._close()` logs an Exception #180

Open nottirb opened 1 month ago

nottirb commented 1 month ago

Bug report

Describe the bug

When a websocket is closed using Socket._close(), it logs the following error:

ERROR:root:Connection with the server closed.
Traceback (most recent call last):
  File "realtime/connection.py", line 141, in _keep_alive
    await self.ws_connection.send(json.dumps(data))
  File "python3.11/site-packages/websockets/legacy/protocol.py", line 635, in send
    await self.ensure_open()
  File "python3.11/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedOK: sent 1000 (OK); then received 1000 (OK)

To Reproduce

Setup a Socket connection and then call Socket._close() using the async method.

Expected behavior

When the socket is explicitly closed by calling Socket._close(), I would expect it to: a) No longer attempt to reconnect b) Not log an error about the connection being closed

System information

nottirb commented 1 month ago

If you'd like to maintain this logging pattern, is it possible to move away from using the root logger -- since it directly impacts the root logger of any app someone builds on top of realtime-py?

Specifically, I could resolve this on my end by suppressing error logging from realtime-py, but because you use the root logger I cannot just target realtime-py with this.