-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
graphql_transport_ws: Fix task shutdown/cancellation issues evident from testsuite warnings #2717
base: main
Are you sure you want to change the base?
graphql_transport_ws: Fix task shutdown/cancellation issues evident from testsuite warnings #2717
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2717 +/- ##
==========================================
- Coverage 96.49% 96.47% -0.03%
==========================================
Files 197 197
Lines 8070 8080 +10
Branches 1457 1463 +6
==========================================
+ Hits 7787 7795 +8
- Misses 180 181 +1
- Partials 103 104 +1 |
Thanks for adding the Here's a preview of the changelog: Minor adjustments for Here's the preview release card for twitter: Here's the tweet text:
|
edf69d3
to
a3264a0
Compare
a3264a0
to
143684f
Compare
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.
I've left some comments, I'm not super familiar with the WS work, though, so I'd wait for @DoctorJohn for a final review.
Oh and since we are changing running code, we should make a release 😊
strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py
Outdated
Show resolved
Hide resolved
# loop cleanup code, similar to code from asyncio.run() | ||
# disabled, can be enabled for debugging | ||
return | ||
|
||
loop = asyncio.get_running_loop() |
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.
could we put this under a if DEBUG_ENABLED
flag? just to make it clearer that it can be used for that?
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.
Sure. The thinking here is that if we are having strange errors/warnings in the unittests, enabling this code to forcefully cleanup tasks after each test fixture should help with isolating the problem. I can also expand on the comment.
|
||
# wait until context is dead. | ||
# We don't know exactly how many packets will arrive or how long it will take. | ||
# Need manual timeout because async timeout doesn't work on async integrations |
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.
Need manual timeout because async timeout doesn't work on async integrations
how come?
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.
Because the actual IO calls are actually blocking, and the event loop running the test will stop until the call returns, so no "async" timeouts can be delivered. And not all of the integrations support a "timeout" parameter to their receive methods.
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.
That said, maybe I can make this test better... I'll have another go at this.
Let's not review this any more until I have had time to clean it up a bit. |
Currently disabled since it can hide other problems present.
f3a8b72
to
daf853b
Compare
@kristjanvalur is this ready for a review? |
I think, since this is a test suite pr, that I'll roll in a fix to the timeout failure for the cancellation test which sometimes shows up. Allow until tomorrow please for me, I have a change to the unit test in mind which doesn't require timeout checks, they are doomed to occasionally fail in a virtualize environment. |
Ok, I found that the problems with the finalizer termination tests are hard to solve right now. The problem is that the iterator/generator created by graphql-core, for iterating over subscriptions, has such weird semantics. The finalizer is actually called on a Task, and may get cancelled during execution. I cannot make good tests for this until we adopt something like PR #2724 |
Examining the warnings after running the unittests for
test_graphql_transport_ws.py
showed some problems in how we were handling task cleanup and cancellation.
Description
within the task, using Finally semantics.
Task
instance should be retrieved at the start, not during shutdown when the event loop may be gone.cleanup_operation
so must not fail if the id isn't on record.As this is not a feature enhancement, a Release file is probably not warranted. Also, this PR belongs in the group of
"subscription enhancements" that I am working on.
Types of Changes
Issues Fixed or Closed by This PR
Checklist