Repository navigation
Conversation
Every DownloaderFactory registered its own bound method with atexit, and the atexit registry holds it until the process exits. The content app builds a factory for every file it streams from a remote, so each streamed file kept a factory, its remote and its closed aiohttp session in memory for the life of the worker. Track the factories in a weak set and close the sessions still open at exit from one atexit hook. Sessions already closed by their owner are skipped, which also avoids running an event loop for them at exit. Closes: pulp#8344
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8344
Every
DownloaderFactoryregistered its own bound_session_cleanupwithatexit, and the atexit registry holds it until the process exits. The content app builds a factory for every file it streams from a remote, so each streamed file kept a factory, its remote and its closed aiohttp session in memory for the life of the worker. Details are in #8344.What changes
weakref.WeakSet, and oneatexithook closes the sessions that are still open at exit. A factory that is no longer used can now be freed._session_cleanupskips a session its owner has already closed, so the exit hook no longer runs an event loop for it (on Python 3.12+ that failed with "There is no current event loop" for every factory ever created, see ClientSession teardown runs after event loop closes #6442).finallyblock as before.Testing
Two unit tests in
test_downloader_factory.py:gc.collect();Both fail without the change.
Reproduction: 300 factories built and closed the way the content handler does it; all 300 are still alive after
gc.collect()on main, none with the change.The pulpcore unit suite gives the same results with and without the change.
Checklist