From 6649e9aba3293272b99ce68232cac4bdff0dc5f3 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 20 Jul 2016 12:45:02 +0100 Subject: [PATCH 1/2] tearDown the project override at the end of each test case self._project.client is a docker.client.Client, so creating a new self._project leaks (via the embedded connection pool) a bunch of Unix socket file descriptors for each test which overrides self.project using this mechanism. In my tests I observed the test harness using 800-900 file descriptor, which is OK on Linux with the default limit of 1024 but breaks on OSX (e.g. with Docker4Mac) where the default limit is only 256. The failure can be provoked on Linux too with `ulimit -n 256`. With this fix I have observed the process ending with ~100 file descriptors open, including 83 Unix sockets, so I think there is likely at least one more leak lurking. Signed-off-by: Ian Campbell --- tests/acceptance/cli_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index dad23bec5..84d401e33 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -114,6 +114,8 @@ class CLITestCase(DockerClientTestCase): for n in networks: if n['Name'].startswith('{}_'.format(self.project.name)): self.client.remove_network(n['Name']) + if hasattr(self, '_project'): + del self._project super(CLITestCase, self).tearDown() From 0483bcb472e2b765fdff4fca1545b32704f93557 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 20 Jul 2016 15:51:22 +0100 Subject: [PATCH 2/2] delete DockerClientTestCase.client class attribute on tearDownClass This is a docker.client.Client and therefore contains a connection pool, so each subclass of DockerClientTestCase can end up holding on to up to 10 Unix socket file descriptors after the tests contained in the sub-class are complete. Before this by the end of a test run I was seeing ~100 open file descriptors, ~80 of which were Unix domain sockets. By cleaning these up only 15 Unix sockets remain at the end (out of ~25 fds, the rest of which are the Python interpretter, opened libraries etc). Signed-off-by: Ian Campbell --- tests/integration/testcases.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/testcases.py b/tests/integration/testcases.py index 8d69d5319..3e33a6c0f 100644 --- a/tests/integration/testcases.py +++ b/tests/integration/testcases.py @@ -63,6 +63,10 @@ class DockerClientTestCase(unittest.TestCase): cls.client = docker_client(Environment(), version) + @classmethod + def tearDownClass(cls): + del cls.client + def tearDown(self): for c in self.client.containers( all=True,