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

Send code 1012 on shutdown for websockets #1816

Merged
merged 5 commits into from
Jan 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions uvicorn/protocols/websockets/websockets_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def __init__(
self.connect_sent = False
self.lost_connection_before_handshake = False
self.accepted_subprotocol: Optional[Subprotocol] = None
self.transfer_data_task: asyncio.Task = None # type: ignore[assignment]
Copy link
Sponsor Member Author

@Kludex Kludex Dec 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to call fail_connection(), because internally there's a check like if hasattr(self, "transfer_data_task"), which should succeed.


self.ws_server: Server = Server() # type: ignore[assignment]

Expand Down Expand Up @@ -145,7 +144,8 @@ def connection_lost(self, exc: Optional[Exception]) -> None:

def shutdown(self) -> None:
self.ws_server.closing = True
self.transport.close()
if not self.transport.is_closing():
Kludex marked this conversation as resolved.
Show resolved Hide resolved
self.fail_connection(1012)

def on_task_complete(self, task: asyncio.Task) -> None:
self.tasks.discard(task)
Expand Down