Skip to content

websocket.receive_bytes() AssertionError  #1369

@hughsw

Description

@hughsw

We have a FastApi/uvicorn websockets service. During testing we can routinely (but not deterministically) trigger an AssertError from websockets.receive_bytes():

Synchrony: 7.45: Synchrony.edge: Exception: AssertionError: error:
Traceback (most recent call last):
  File "/app/synchrony.py", line 190, in edge
    if await call() is None: break
  File "/app/synchrony.py", line 170, in recv
    payload = await websocket.receive_bytes()
  File "/usr/local/lib/python3.9/site-packages/starlette/websockets.py", line 89, in receive_bytes
    assert self.application_state == WebSocketState.CONNECTED
AssertionError

This happens (sometimes) during testing when we $ kill <clientPID> an active client that is using the service. That is, when the connection to the service is abruptly terminated. When we stand up the same service behind PyPi websockets we do not see such a failure.

For each connection there are multiple async tasks running. Another task is doing await websocket.close(), which triggers a RuntimeError in deep in the starlette async close code, prior to (or concurrent with) the above failure. Documentation is hard to find, so it's not clear that starlette websockets promise an idempotent close() method. Nonetheless, AssertionError, by definition, means there's a code issue...

If there is interest I can post other (large) related stack traces.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions