Skip to content

_handle_ping_event() occasionally sends to closed socket #184

Open
@brandyn

Description

@brandyn

The short of it is that _handle_ping_event() sometimes tries to send a reply to a closing socket, which raises an (avoidable) exception from within the websocket thread.

This can lead to unexpected MultiErrors crashing the app. That should be improved with python 3.11's ExceptionGroups, but still there's no reason for websockets to be throwing this particular exception while closing down a pipe.

Here is the exception:

  Traceback (most recent call last):
    File ".../python3.10/site-packages/trio_websocket/_impl.py", line 1205, in _reader_task
      await handler(event)
    File ".../python3.10/site-packages/trio_websocket/_impl.py", line 1145, in _handle_ping_event
      await self._send(event.response())
    File ".../python3.10/site-packages/trio_websocket/_impl.py", line 1249, in _send
      data = self._wsproto.send(event)
    File ".../python3.10/site-packages/wsproto/__init__.py", line 64, in send
      data += self.connection.send(event)
    File ".../python3.10/site-packages/wsproto/connection.py", line 107, in send
      raise LocalProtocolError(
  wsproto.utilities.LocalProtocolError: Event Pong(payload=bytearray(b'')) cannot be sent in state ConnectionState.LOCAL_CLOSING.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions