-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 WebSocket ping tasks being prematurely garbage collected #8641
Conversation
The event loop only keeps weak references to tasks, we need to hold a strong reference to ensure that the ping task is not prematurely garbage collected. https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task In almost all cases the ping can be done synchronously if the task is created eagerly which avoids scheduling the ping task on the event loop. fixes #8614
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8641 +/- ##
=======================================
Coverage 97.93% 97.93%
=======================================
Files 107 107
Lines 33669 33721 +52
Branches 3952 3959 +7
=======================================
+ Hits 32974 33026 +52
Misses 515 515
Partials 180 180
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Backport to 3.10: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 0a88bab on top of patchback/backports/3.10/0a88bab39f922e5a1775a4f557a1475d42a5a504/pr-8641 Backporting merged PR #8641 into master
🤖 @patchback |
Backport to 3.11: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 0a88bab on top of patchback/backports/3.11/0a88bab39f922e5a1775a4f557a1475d42a5a504/pr-8641 Backporting merged PR #8641 into master
🤖 @patchback |
(cherry picked from commit 0a88bab)
(cherry picked from commit 0a88bab)
…aturely garbage collected (#8646)
…aturely garbage collected (#8647)
What do these changes do?
The event loop only keeps weak references to tasks, we need to hold a strong reference to ensure that the ping task is not prematurely garbage collected.
https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task
In almost all cases the ping can be done synchronously if the task is created eagerly which avoids scheduling the ping task on the event loop.
Are there changes in behavior for the user?
no
Is it a substantial burden for the maintainers to support this?
no
Related issue number
fixes #8614