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.

Title: Awaiting multiple times on same task increases memory usage unboundedly
Type: Stage: resolved
Components: asyncio Versions: Python 3.11, Python 3.10, Python 3.9
Status: closed Resolution: duplicate
Dependencies: Superseder: Incorrect traceback when future's exception is raised multiple times
View: 45924
Assigned To: Nosy List: asvetlov, davidmanzanares, iritkatriel, yselivanov
Priority: normal Keywords:

Created on 2022-03-08 09:51 by davidmanzanares, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit davidmanzanares, 2022-03-08 09:51 Script to reproduce
Messages (2)
msg414739 - (view) Author: David M. (davidmanzanares) Date: 2022-03-08 09:51
Awaiting multiple times on a single task that failed with an exception results in an unbounded increase in memory usage. Enough repeated "await"s of the task can result in an OOM.

The same pattern on a task that didn't raise an exception behaves as expected.

The attached short script ends up using more than 1GB of memory in less than a minute.
msg414812 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-09 20:24
This is a duplicate of bpo-45924.  The traceback accumulates another frame every time the exception is raised. To see that, change main in your script to 

async def main():
    task = asyncio.create_task(task_that_raise())
    while True:
            await task
        except Exception as e:

and notice that in the output, X grows every time in the line like

    [Previous line repeated X more times]
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91110
2022-03-09 20:24:30iritkatrielsetstatus: open -> closed

superseder: Incorrect traceback when future's exception is raised multiple times
versions: - Python 3.7, Python 3.8
nosy: + iritkatriel

messages: + msg414812
resolution: duplicate
stage: resolved
2022-03-08 09:51:03davidmanzanarescreate