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.
We have a FastApi/uvicorn websockets service. During testing we can routinely (but not deterministically) trigger an AssertError from
websockets.receive_bytes():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.