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

close file handles after executing commands in containers #582

Merged
merged 1 commit into from
Feb 12, 2023

Conversation

felixfontein
Copy link
Collaborator

@felixfontein felixfontein commented Feb 11, 2023

SUMMARY

Cherry-picked docker/docker-py@34e6829.

Ref: #435

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

vendored Docker SDK for Python

…py#2320)

Requests with stream=True MUST be closed or else the connection will
never be returned to the connection pool. Both ContainerApiMixin.attach
and ExecApiMixin.exec_start were leaking in the stream=False case.
exec_start was modified to follow attach for the stream=True case as
that allows the caller to close the stream when done (untested).

Tested with:

    # Test exec_run (stream=False) - observe one less leak
    make integration-test-py3 file=models_containers_test.py' -k test_exec_run_success -vs -W error::ResourceWarning'
    # Test exec_start (stream=True, fully reads from CancellableStream)
    make integration-test-py3 file=api_exec_test.py' -k test_execute_command -vs -W error::ResourceWarning'

After this change, one resource leak is removed, the remaining resource
leaks occur because none of the tests call client.close().

Fixes docker/docker-py#1293
(Regression from docker/docker-py#1130)

Cherry-picked from docker/docker-py@34e6829

Co-authored-by: Peter Wu <[email protected]>
Co-authored-by: Milas Bowman <[email protected]>
Copy link

@kristianheljas kristianheljas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@felixfontein felixfontein merged commit 983b2b4 into ansible-collections:main Feb 12, 2023
@felixfontein felixfontein deleted the docker-py-2 branch February 12, 2023 07:29
@felixfontein
Copy link
Collaborator Author

@kristianheljas thanks a lot for reviewing this!

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.

2 participants