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

Fixes websockets implementation where handshake fails left tasks pending #921

Merged
merged 2 commits into from
Dec 29, 2020

Conversation

euri10
Copy link
Member

@euri10 euri10 commented Dec 28, 2020

Fixes #920

Probably the one liner that took me the most time ! Hopefully it's the right move.....

log after fix

Switched to a new branch '920_flaky_ws_tests'
❯ 
❯ 
❯ pytest -k test_missing_handshake
========================================================================================================================== test session starts ==========================================================================================================================
platform linux -- Python 3.8.6, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /home/lotso/PycharmProjects/uvicorn, configfile: setup.cfg
plugins: mock-3.4.0, asyncio-0.14.0
collected 213 items / 211 deselected / 2 selected                                                                                                                                                                                                                       

tests/protocols/test_websocket.py ..                                                                                                                                                                                                                              [100%]

=================================================================================================================== 2 passed, 211 deselected in 0.84s ===================================================================================================================
❯ pytest -k test_send_before_handshake
========================================================================================================================== test session starts ==========================================================================================================================
platform linux -- Python 3.8.6, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /home/lotso/PycharmProjects/uvicorn, configfile: setup.cfg
plugins: mock-3.4.0, asyncio-0.14.0
collected 213 items / 211 deselected / 2 selected                                                                                                                                                                                                                       

tests/protocols/test_websocket.py ..                                                                                                                                                                                                                              [100%]

=================================================================================================================== 2 passed, 211 deselected in 0.81s ===================================================================================================================
  ~/PycharmProjects/uvicorn   920_flaky_ws_tests ?6 ❯  

Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

Woohoo 🙌

@@ -135,6 +135,7 @@ def send_500_response(self):
msg,
]
self.transport.write(b"".join(content))
self.handshake_started_event.set()
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a comment about why we're doing this? :)

For example...?

"Allow handler task to terminate cleanly, as websockets doesn't cancel it by itself."

Copy link
Member Author

Choose a reason for hiding this comment

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

yes it's the kind of stuff you easily forget why it was put there ! I also added a reference to te issue.

@euri10 euri10 merged commit 091571b into encode:master Dec 29, 2020
@euri10 euri10 deleted the 920_flaky_ws_tests branch December 29, 2020 07:40
@florimondmanca florimondmanca mentioned this pull request Dec 29, 2020
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.

Websockets implementation does not clean properly tasks if handshake fails
2 participants