-
-
Notifications
You must be signed in to change notification settings - Fork 758
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 1230; don't call ensure_open in WebSocketProtocol.asgi_receive #1252
Fix 1230; don't call ensure_open in WebSocketProtocol.asgi_receive #1252
Conversation
ok, cant say I'm following everything here as it's been quite a while, |
second thing, this may be a good idea to come up with tests for this |
Hey @euri10 Indeed, this PR keeps the original fix to #244 , written by @adamhooper and outlined in this PR: #704 Small changes were made Adam Hooper's code because the websockets library has changed since then; The I also added a test that ensures the bug I found in #1230 doesn't come back. It's worth noting that this test immediately passed for the |
Hey @euri10 I just rolled back the code in In In other words, this is preexisting behavior, and is not related to calling I don't know the websocket spec well enough to know whether the correct close code in this situation is Here's what the tests printed out:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let's roll with this, thanks for the digging into finding the root cause of this @kylebebak
let's keep in mind that websocket close code discrepancy, not sure I wont forget since I'm not using that part of the library but never knows !
Thank you @euri10 for all the feedback and helping to get this merged! I agree that it could be good to open an issue pointing out the discrepancy between the close codes when the server rejects the connection using I think this issue here has all the context we need. If you want to open an issue, we can just point to this PR |
in all honesty I dont know, 0.15.0 was mid august iirc and I've been afk most of the time since so really cant say without looking more closely at what has been pushed |
Thanks for clarifying guys! |
Closes #1230. Reverts most of 9a3040c
We can't call
WebSocketCommonProtocol.ensure_open
before callingWebSocketCommonProtocol.recv
, because there may be unread frames in the server's read queue that were sent by the client before the client sent the close frame. See this comment from the websockets source codeWebSocketCommonProtocol.ensure_open
raises an exception and prevents the server from reading these unread frames. Neither the client, nor application code using uvicorn, has any way of knowing that frames successfully sent by the client to the server's read queue, before any close frame was sent, will never be read by the server.The spec is clear on this: https://datatracker.ietf.org/doc/html/rfc6455#section-1.4
The current behavior in uvicorn is rather "a peer discards any further data received, and any data previously received"
Also worth noting, python-websockets/websockets#670 was eventually closed without any changes being made; in other words, there was no bug in
websockets
, and the maintainer agrees that callingawait self.ensure_open()
inrecv
is incorrectI tested
uvicorn
after making these changes, and the behavior is as expected; the server can read frames in the read queue after a close frame is sent by the client, as long as those frames were sent before the close frame