This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Task created by StreamReaderProtocol gets garbage collected.
Type: behavior Stage: patch review
Components: asyncio Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, kumaraditya, simwr872, yselivanov
Priority: normal Keywords: patch

Created on 2022-01-08 23:35 by simwr872, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
example.py simwr872, 2022-01-08 23:35
Pull Requests
URL Status Linked Edit
PR 30505 open simwr872, 2022-01-09 17:05
Messages (3)
msg410124 - (view) Author: Simon Wrede (simwr872) * Date: 2022-01-08 23:35
Documentation states that a reference must be kept when creating a task, https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task.

This is not done in StreamReaderProtocol, https://github.com/python/cpython/blob/main/Lib/asyncio/streams.py#L244.

I've provided a simple example to force garbage collection of this task which results in `Task was destroyed but it is pending!`. Uncommenting the commented code of the example shows that the task is not destroyed when a reference is kept.

Am I missing something or using the library incorrectly? I've followed the examples at https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-server-using-streams.
msg410134 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-01-09 07:20
Thanks for the bug report.

Seems like your analysis is correct.

Could you make a pull request which adds a task reference?
msg410310 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-01-11 15:54
I'm removing 3.7 and 3.8 from the "versions" field, since those branches are old enough that they're now only accepting security-related patches.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90467
2022-01-11 15:54:38AlexWaygoodsetnosy: - AlexWaygood
2022-01-11 15:54:26AlexWaygoodsetnosy: + AlexWaygood

messages: + msg410310
versions: - Python 3.7, Python 3.8
2022-01-11 15:42:46simwr872setversions: + Python 3.7, Python 3.8, Python 3.9, Python 3.11
2022-01-09 17:05:50simwr872setkeywords: + patch
stage: patch review
pull_requests: + pull_request28710
2022-01-09 07:56:19kumaradityasetnosy: + kumaraditya
2022-01-09 07:20:55asvetlovsetmessages: + msg410134
2022-01-08 23:37:52simwr872settype: behavior
2022-01-08 23:35:55simwr872create