Leaking file descriptors
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
There are two places where file descriptors are being leaked , at least with python 3.8:
_get_raw_response_socket():in case of Unix sockets, additional referencing seems to stop them from being closed- When
DockerClientis not used as a context manager it does not callclose()on the api session object.
I have managed to work around with:
class FixedAPIClient(docker.APIClient):
def _get_raw_response_socket(self, response):
sock = super()._get_raw_response_socket(response)
if self.base_url.startswith('http+docker://'):
sock._response = None
return sock
class FixedDockerClient(docker.DockerClient):
def __init__(self, *args, **kwargs):
self.api = FixedAPIClient(*args, **kwargs)
def __del__(self):
try:
if self.api:
self.api.close()
except AttributeError:
pass
Our setup is quite complex. If you believe this should not happen and it is a corner case I will try to come up with a minimal example.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reducing the reported setup to a minimal reproduction for the two paths: _get_raw_response_socket() with Unix sockets and DockerClient used without a context manager. Inspect how the API session is created and closed, then verify that both paths release their file descriptors without relying on the workaround shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100