Skip to content

Leaking file descriptors #2766

Description

@srdjan-catalyst

There are two places where file descriptors are being leaked , at least with python 3.8:

  1. _get_raw_response_socket(): in case of Unix sockets, additional referencing seems to stop them from being closed
  2. When DockerClient is not used as a context manager it does not call close() 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions