[issue41229] Asynchronous generator memory leak

Nathaniel Smith report at bugs.python.org
Sun Jul 19 06:04:50 EDT 2020


Nathaniel Smith <njs at pobox.com> added the comment:

Huh, this is very weird. I can confirm that the async generator objects aren't cleaned up until loop shutdown on asyncio.

On the trio main branch, we don't yet use the `set_asyncgen_hooks` mechanism, and the async generator objects are cleaned up immediately.

However, if I check out this PR that will add it: https://github.com/python-trio/trio/pull/1564

...then we see the same bug happening with Trio: all the async generators are kept around until loop shutdown.

Also, it doesn't seem to be a circular references issue – if I explicitly call `gc.collect()`, then the asyncgen destructors are still *not* called; only shutting down the loop does it.

This doesn't make any sense, because asyncio/trio only keep weak references to the async generator objects, so they should still be freed.

So maybe the `set_asyncgen_hooks` code introduces a reference leak on async generator objects, or something?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41229>
_______________________________________


More information about the Python-bugs-list mailing list