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

Conceptual question about WebSockets codes #364

Closed
Kludex opened this issue Dec 27, 2022 · 4 comments
Closed

Conceptual question about WebSockets codes #364

Kludex opened this issue Dec 27, 2022 · 4 comments

Comments

@Kludex
Copy link
Contributor

Kludex commented Dec 27, 2022

Hi there 👋

When the handshake fails, what is the ASGI server supposed to send to the ASGI application?

Since the handshake failed, uvicorn sends a 500 to the client, and is sending a websocket.disconnect with 1006 code to the application. But... That code is "fake", as I'm not sending it to the client.

What should be the expectation here? What should we send to the application?

@andrewgodwin
Copy link
Member

1006 is the code for "we couldn't close the connection cleanly" (see https://www.rfc-editor.org/rfc/rfc6455.html) so it's the best one to use in this situation IMO!

@Kludex
Copy link
Contributor Author

Kludex commented Dec 27, 2022

But the client is going to receive 500 status code. Is it fine? 🤔

@andrewgodwin
Copy link
Member

Yes - the close code is not guaranteed to be what the client gets, and the spec says specifically in the case of an abnormal connection closure that 1006 is what to send.

@Kludex
Copy link
Contributor Author

Kludex commented Dec 27, 2022

Aha. Perfect.

Thanks Andrew! 😁🙏

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

No branches or pull requests

2 participants