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

Fix shutdown event in Websocket Implementations #1738

Closed
wants to merge 6 commits into from

Conversation

iudeen
Copy link
Contributor

@iudeen iudeen commented Oct 28, 2022

No description provided.

@iudeen
Copy link
Contributor Author

iudeen commented Oct 28, 2022

Current websockets implementation is giving status code 1006, which is not right.

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame.

Ref: https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1

This implies in websockets implementation, connections are not gracefully closed when the server is shutdown.

@iudeen
Copy link
Contributor Author

iudeen commented Oct 28, 2022

As per MDN even 1012 is wrong. The right response code should be 1001.

@Kludex
Copy link
Member

Kludex commented Oct 28, 2022

See django/asgiref#340 for WebSocket codes on disconnect/close.

@iudeen
Copy link
Contributor Author

iudeen commented Oct 28, 2022

So 1005 then? There is already a PR, but that is for disconnect. Is it the same for shutdown?

self.transport.close()
task = asyncio.create_task(self.close(code=1012))
task.add_done_callback(self.on_task_complete)
self.tasks.add(task)

Copy link
Contributor Author

@iudeen iudeen Oct 28, 2022

Choose a reason for hiding this comment

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

Help needed here.

self.transport.close() causes unexpected closure of connection at this place. However the transport is getting closed at a later stage. Is this okay?

@iudeen iudeen changed the title Tests shutdown event in Websocket Implementations Fix shutdown event in Websocket Implementations Oct 28, 2022
@Kludex
Copy link
Member

Kludex commented Oct 29, 2022

I've added the tests for shutdown on #1737. 🙏

@iudeen
Copy link
Contributor Author

iudeen commented Oct 29, 2022

Ok, cool! I'll close this PR then.

@iudeen iudeen closed this Oct 29, 2022
@iudeen iudeen deleted the fix/websockets-coverage-imprv branch October 29, 2022 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants