Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 938127 - sys-apps/portage: _wrap_loop function returns redundant AsyncioEventLoop instances that are garbage collected
Summary: sys-apps/portage: _wrap_loop function returns redundant AsyncioEventLoop inst...
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on: 933499
Blocks:
  Show dependency tree
 
Reported: 2024-08-18 02:19 UTC by Zac Medico
Modified: 2024-09-11 01:30 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zac Medico gentoo-dev 2024-08-18 02:19:51 UTC
I've noticed that the _wrap_loop function returns redundant _AsyncioEventLoop instances that are garbage collected, which means that any attached _coroutine_exithandlers related to bug 937740 will be lost.

I'm working on a patch to fix this by using the _safe_loop function to lookup the appropriate _AsyncioEventLoop instance for the current thread.
Comment 1 Zac Medico gentoo-dev 2024-08-18 15:31:34 UTC
Ultimately the loop arguments that necessitate the _wrap_loop function can be removed, because our aim since bug 761538 should be to eliminate them. Meanwhile, we don't want _wrap_loop to return redundant AsyncioEventLoop instances if we can easily prevent it.
Comment 2 Larry the Git Cow gentoo-dev 2024-08-19 14:49:13 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=e97acd3c62ff02eb41ff643e75eb5e07c27717f8

commit e97acd3c62ff02eb41ff643e75eb5e07c27717f8
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2024-08-18 14:59:46 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2024-08-18 15:46:45 +0000

    _wrap_loop: Prevent redundant AsyncioEventLoop instances
    
    Ultimately the loop arguments that necessitate the _wrap_loop
    function can be removed, because our aim since bug 761538 should
    be to eliminate them. Meanwhile, we don't want _wrap_loop to return
    redundant AsyncioEventLoop instances if we can easily prevent it.
    
    Therefore, use _safe_loop(create=False) to look up the AsyncioEventLoop
    instance associated with the current thread, and avoid creating
    redundant instances. This serves to guard against garbage collection
    of AsyncioEventLoop instances which may have _coroutine_exithandlers
    added by the atexit_register function since commit cb0c09d8cecb from
    bug 937740.
    
    If _safe_loop(create=False) fails to associate a loop with the current
    thread, raise an AssertionError for portage internal API consumers.
    It's not known whether external API consumers will trigger this case,
    so if it happens then emit a UserWarning and return a temporary
    AsyncioEventLoop instance.
    
    Fixes: cb0c09d8cecb ("Support coroutine exitfuncs for non-main loops")
    Bug: https://bugs.gentoo.org/938127
    Bug: https://bugs.gentoo.org/937740
    Bug: https://bugs.gentoo.org/761538
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/util/futures/_asyncio/__init__.py | 43 +++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 5 deletions(-)
Comment 3 Larry the Git Cow gentoo-dev 2024-09-11 01:30:54 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=02d0e00a1ba811b39140d10e17488f7fc3916534

commit 02d0e00a1ba811b39140d10e17488f7fc3916534
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-09-11 01:30:10 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-09-11 01:30:30 +0000

    sys-apps/portage: add 3.0.66
    
    Closes: https://bugs.gentoo.org/435066
    Closes: https://bugs.gentoo.org/907061
    Closes: https://bugs.gentoo.org/910560
    Closes: https://bugs.gentoo.org/933433
    Closes: https://bugs.gentoo.org/934220
    Closes: https://bugs.gentoo.org/934514
    Closes: https://bugs.gentoo.org/934784
    Closes: https://bugs.gentoo.org/935830
    Closes: https://bugs.gentoo.org/936273
    Closes: https://bugs.gentoo.org/937384
    Closes: https://bugs.gentoo.org/937485
    Closes: https://bugs.gentoo.org/937740
    Closes: https://bugs.gentoo.org/937888
    Closes: https://bugs.gentoo.org/937891
    Closes: https://bugs.gentoo.org/938127
    Closes: https://bugs.gentoo.org/933499
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-apps/portage/Manifest              |   1 +
 sys-apps/portage/portage-3.0.66.ebuild | 227 +++++++++++++++++++++++++++++++++
 2 files changed, 228 insertions(+)