Skip to content

Django, Channels, Uvicorn: "Unexpected ASGI message" #2008

Answered by SHxKM
SHxKM asked this question in Help!
Discussion options

You must be logged in to vote

So I think I found the root cause, I think.

The websockets library (utilized by asyncio, utilized by uvicorn) closes the websocket here:

https://github.com/python-websockets/websockets/blob/fe629dede6eb083013e0d2373d5c3120c0078db3/src/websockets/legacy/server.py#L257-L265

...and only then Channels disconnect() method is being called. By the time disconnect() is called, the websocket is already closed, so when we call self.close() - we get the exception.

So now the question is (@carltongibson if you can chime in that'd be great):

Is this expected? is it problematic can I safely remove self.close() from disconnect()?
How do we deal with this if at all? it seems a bit limiting that disconnect()

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@SHxKM
Comment options

@carltongibson
Comment options

@SHxKM
Comment options

@SHxKM
Comment options

Answer selected by carltongibson
@carltongibson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help!
Labels
None yet
2 participants