Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/ssh: Fix atexit.register() SshConnection leak #679

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

douglas-raillard-arm
Copy link
Contributor

@douglas-raillard-arm douglas-raillard-arm commented Mar 28, 2024

SshConnection registers an atexit handler so the connection is closed upon exiting the process if it has not been done before. However, the handler keeps a reference on the connection, which means it will stay alive. If lots of short-lived connections are created (which can happen when using e.g. ThreadPoolExecutor), they will simply stay around and leak.

Fix that by using a weak reference (WeakMethod) to register in the atexit handler, with a callback to unregister it when the object is deallocated.

Fixes #676

SshConnection registers an atexit handler so the connection is closed
upon exiting the process if it has not been done before. However, the
handler keeps a reference on the connection, which means it _will_ stay
alive. If lots of short-lived connections are created (which can happen
when using e.g. ThreadPoolExecutor), they will simply stay around and
leak.

Fix that by using a weak reference (WeakMethod) to register in the
atexit handler, with a callback to unregister it when the object is
deallocated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

atexit handler leaks connection instances
2 participants