-
-
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
Warnings when running tests using the graphql-transport-ws websocket protocol #2720
Comments
Hey @rjwills28 thanks for the detailed report. This issue has been brought up before, recently in #2460 for example. Whenever it was brought up it kinda stalled, presumably because it doesn't really affect production (the timeout will just run out and the task ends)?
That's a great question. The graphql-transport-ws protocol doesn't define a default, so we just went with a minute and made it configurable. Maybe lowering the default is a good call. Need to do some research on the defaults of other implementations.
I'm very much in favour of the second suggestion. Feel free to open a PR! (there are a decent amount of graphql-transport-ws PRs open right now, I'll review them as soon as I find some time. Maybe check first whether one of them is already addressing this issue). |
Thanks for the prompt response and feedback on this issue. I've had a look through the open PRs and it looks like PR #2703 would fix the pytest warnings as it includes a clean-up of the On a related note, I just updated to the most recent version of Strawberry (0.171.2) and now as well as the simple warnings I am also getting the following exceptions:
I think this is coming from the change in this recent commit. On line 301 of strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py we As I said, I do not see the warnings or exceptions when running against the code in PR #2703 so maybe this is worth looking at unless we want an intermediate fix. |
We are using Strawberry to build our GraphQL server and have noticed a possible issue when running tests with pytest using an aiohttp test client to open a websocket and subscribe using the new graphql-transport-ws protocol. We get the follow warning after the tests have finished:
I have taken a look into the code based on this message and I think I have found out what is happening. Essentially an
asyncio.sleep()
task is created and run (here). The default time for the sleep is passed in as 60 secs from the GraphQLView instantiation. After the 60 sec sleep this method just checks whether the init_connection message was received. The 60 secasyncio.sleep()
is not a problem when actually running the server as the server runs for long enough for this time to elapse, or it is killed. However in the test scenario we create a subscription, check the results and then the tests complete, closing the event loop, which all takes less than 60 secs and hence we get the warning that the sleep task was 'destroyed but it it pending!'.As a work-around we create a custom GraphQLView and set the
connection_init_wait_timeout
to a much smaller value (e.g. 5 sec). This stops the warning as theasyncio.sleep()
task can complete in this time, before we close the event loop.Question: We were just wondering whether there is a reason for a default connection_init_wait_timeout of 60 secs that we have missed?
I also wonder whether there may be a better way of managing the long
asyncio.sleep()
task to check theconnection_init_received
status. Here are 2 suggestions that might improve the behaviour:connection_init message
has been received with a short sleep in between and timeout if we do not receive it after 60 secs. This will cause the task to complete as soon as theconnection_init message
has been received instead of waiting the arbitrary 60 secs. It also means we do not have a longasyncio.sleep()
task.asyncio.sleep(60)
task is still running and cancels it if it is.Any thoughts/feedback appreciated. Thanks!
Upvote & Fund
The text was updated successfully, but these errors were encountered: