Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket.disconnect events are not sent to applications when clients don’t close connections properly (wsproto only) #997

Closed
2 tasks done
sephioh opened this issue Mar 10, 2021 · 1 comment · Fixed by #996

Comments

@sephioh
Copy link
Contributor

sephioh commented Mar 10, 2021

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

When WebSocket connections are not properly closed by clients, uvicorn + wsproto leaves one zombie asyncio tasks running per connection and do not emit disconnect events to applications.

To reproduce

  1. Start any application with uvicorn using wsproto;
  2. Create a websocket connection;
  3. Do not close the websocket properly;
  4. Observe that no websocket.disconnect events have been sent to your application;
  5. Check for all asyncio tasks (asyncio.all_tasks()): there should be a zombie run_asgi task for each non properly closed connection.

I’ve setup this repo with instructions to make it easier to reproduce this issue: https://github.com/sephioh/uvicorn-wsproto-issue

Expected behavior

A disconnect event should be sent to applications.

Actual behavior

Disconnect event are not being sent to apps when client socket loss happens.

Environment

Running uvicorn 0.13.4 with CPython 3.9.0 on Linux
Must be executed with wsproto (—ws wsproto).

Additional context

https://docs.python.org/3/library/asyncio-protocol.html#asyncio.BaseProtocol.connection_lost

No problems are found when running with websockets impl (—ws websockets).

I’ve opened a PR with a possible fix: #996

@Kludex
Copy link
Sponsor Member

Kludex commented Oct 29, 2022

This will be available on Uvicorn 0.20.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants