Skip to content

close file handles after executing commands in containers#582

Merged
felixfontein merged 1 commit intoansible-collections:mainfrom
felixfontein:docker-py-2
Feb 12, 2023
Merged

close file handles after executing commands in containers#582
felixfontein merged 1 commit intoansible-collections:mainfrom
felixfontein:docker-py-2

Conversation

@felixfontein
Copy link
Copy Markdown
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 <pwu@cloudflare.com>
Co-authored-by: Milas Bowman <milas.bowman@docker.com>
Copy link
Copy Markdown

@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
Copy Markdown
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