Skip to content

Prevent update handling task pointers from being garbage collected, backport of #1328 #1331

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

Merged
merged 3 commits into from
Oct 8, 2023

Conversation

Kylmakalle
Copy link
Contributor

@Kylmakalle Kylmakalle commented Oct 7, 2023

Description

This is a backport of #1328 to mitigate possible issues like #628, #927. As in #1328, this PR preserves asyncio Task pointers until the task is completed to ensure Task will not be garbage collected and disappear. See recommendations in Python docs.

Important: Save a reference to the result of this function, to avoid a task disappearing mid-execution. The event loop only keeps weak references to tasks. A task that isn’t referenced elsewhere may get garbage collected at any time, even before it’s done. For reliable “fire-and-forget” background tasks, gather them in a collection

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Honestly, I don't have a v3-based bot with workload I have in v2. But want to admit once again, it's a pretty rare case and we're handling it as the docs says.

Test Configuration:

  • Operating System: Macos, Linux
  • Python version: 3.11.1

@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Oct 7, 2023
@github-actions
Copy link

github-actions bot commented Oct 7, 2023

✔️ Changelog found.

Thank you for adding a description of the changes

@Kylmakalle
Copy link
Contributor Author

I've not seen any evidence of "Task was destroyed but it is pending" for v3 yet, but I assume it's due to a lower adoption rate than v2.

@Kylmakalle Kylmakalle changed the title Preserve update handling task pointers, backport of #1328 Prevent update handling task pointers from being garbage collected, backport of #1328 Oct 7, 2023
@codecov
Copy link

codecov bot commented Oct 8, 2023

Codecov Report

Merging #1331 (cd3dc7c) into dev-3.x (6738255) will not change coverage.
Report is 1 commits behind head on dev-3.x.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1331   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          369       369           
  Lines         9429      9435    +6     
=========================================
+ Hits          9429      9435    +6     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
aiogram/dispatcher/dispatcher.py 100.00% <100.00%> (ø)
aiogram/webhook/aiohttp_server.py 100.00% <100.00%> (ø)

@JrooTJunior JrooTJunior merged commit cad4258 into aiogram:dev-3.x Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issue or PR for stable 3.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants