-
-
Notifications
You must be signed in to change notification settings - Fork 556
Description
I have a misbehaving server (embedded device, nothing I can do about it) that, after a client sends a CLOSE frame, responds with a frame containing an invalid opcode (15). The python-websockets protocol parsing code does notice this and raises ProtocolError("invalid opcode")
, but somehow the asyncio client silently swallows this. My script then just hangs rather than at least bubbling the exception up to the top level and dying. I'm not sure if the invalid opcode is a problem just in response to CLOSE, or if it would hang the client at any point.
Below is a minimal reproducer using the asyncio client, if you can somehow put together your own ws server script that sends an invalid opcode. Expected behavior is for this script to silently exit immediately. On my misbehaving server, it hangs indefinitely. It also takes two Ctrl-C presses to interrupt, if that means anything.
In addition to not cleanly exiting when the script is finished, any exceptions that occur within the async with
block are never reported up. You can replace the pass
in the script below with raise Exception
and it still hangs indefinitely without showing a traceback.
import asyncio
from websockets.asyncio.client import connect
endpoint = ...
async def func():
async with connect(endpoint) as websocket:
pass
if __name__ == "__main__":
asyncio.run(func())