Do not block graphql_transport_ws operations while creating context or validating a single request operation#2829
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2829 +/- ##
==========================================
- Coverage 96.79% 96.53% -0.27%
==========================================
Files 517 517
Lines 33517 33598 +81
Branches 5570 5573 +3
==========================================
- Hits 32444 32433 -11
- Misses 845 926 +81
- Partials 228 239 +11 |
33caef4 to
2008261
Compare
|
Thanks for adding the Here's a preview of the changelog: Operations over Here's the tweet text: |
bd252c1 to
a8f064c
Compare
a8f064c to
c6044e5
Compare
c6044e5 to
94e545e
Compare
|
Thanks for updating @kristjanvalur, still validating the changes 👍 |
94e545e to
716a64b
Compare
716a64b to
bc69cdd
Compare
4377cfb to
1117caf
Compare
eb34b88 to
f2632d0
Compare
5ee6010 to
d17a4d4
Compare
7058795 to
03689c0
Compare
03689c0 to
a1d0695
Compare
|
PR is updated but I cannot see from the codecov that there is any missing coverage for my changes. |
|
This PR needs to be completely refactored because of the upstream changes. |
Hi Kristján, thanks for bringing this up again! During a brief discussion of this PR at PyconIT earlier this year, I realized that the strawberry core devs I talked to generally perceive Based on the assumption that these operations are lightweight, we were less concerned about |
|
Sounds good. I'll leave the context/root as they are and rework this to just do the validation. |
|
It appears that validation now happens in the task ,because the |
|
Actually, my tests as written for the old PR do indicate a discrepancy in validation handling for queries vs subscriptions. |
|
By the way, speaking of "context" being created once for each WS connection, I want to draw your attention to this bug: #1754 |
bellini666
left a comment
There was a problem hiding this comment.
My $.02 cents in here, leaving for @DoctorJohn to actually approve this once it is ready
| async def handle_connection_init_timeout(self) -> None: | ||
| task = asyncio.current_task() | ||
| assert task | ||
| assert task is not None # for typecheckers |
There was a problem hiding this comment.
nit: since we enforce typing a lot here, assert <something> is a well known practice for type checkers, so I don't think the comment is required
| assert task is not None # for typecheckers | |
| assert task is not None |
| await operation.send_message(CompleteMessage(id=operation.id)) | ||
| finally: | ||
| # Close the AsyncGenerator in case of errors or cancellation | ||
| await result_source.aclose() |
There was a problem hiding this comment.
Should this be wrapped in a with suppress(asyncio.CancelledError)?
Thanks for verifying! It looks like this was changed when extension support for subscriptions was added. Let's close this PR then.
Thank you so much for highlighting that. I'll check the specs and the PR introducing this discrepancy again. It looks like something slipped through the review and had no proper tests.
👍 Currently reading through it. |

Now both
Contextcreation and validation of an operation (subscripton or single-result operation) are performedon the worker task, freeing up the Websocket for other requests.
Description
Previously both creating the context, and validating the request, were done on the same task which handles
incoming messages for the Websocket. Both of these operations are async and can potentially take a long time.
Now they are performed on the worker background
Taskwhich is created to handle the operation.We add tests to make sure that long operations in context and validation don't block the websocket connection.
Types of Changes
Issues Fixed or Closed by This PR
Checklist