From e29f7991201bbf5160bd181f6b3bd318fa7b8c70 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 16 Mar 2021 12:54:37 +0100 Subject: [PATCH 1/2] Close urllib3 pool before swapping the server into the "inactive" list --- src/crate/client/http.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/crate/client/http.py b/src/crate/client/http.py index ef96d614..1f81c631 100644 --- a/src/crate/client/http.py +++ b/src/crate/client/http.py @@ -568,6 +568,15 @@ def _drop_server(self, server, message): """ Drop server from active list and adds it to the inactive ones. """ + + # Try to close resource first. + try: + self.server_pool[server].close() + except Exception as ex: + logger.warning("When removing server from active pool, " + "resource could not be closed: %s", ex) + + # Apply bookkeeping. try: self._active_servers.remove(server) except ValueError: @@ -576,7 +585,7 @@ def _drop_server(self, server, message): heapq.heappush(self._inactive_servers, (time(), server, message)) logger.warning("Removed server %s from active pool", server) - # if this is the last server raise exception, otherwise try next + # If this is the last server, raise an exception. if not self._active_servers: raise ConnectionError( ("No more Servers available, " From 89507a0fb9fc835831945bfe1ccfd3d1ef019ed4 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Fri, 26 Mar 2021 11:18:16 +0100 Subject: [PATCH 2/2] Increase serverpool retry interval within test scenarios This will hopefully resolve some flakyness where the swapping on the bookeeping between the list of active/inactive servers occurs too quickly. --- src/crate/client/test_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crate/client/test_http.py b/src/crate/client/test_http.py index b90b992e..5ef8203a 100644 --- a/src/crate/client/test_http.py +++ b/src/crate/client/test_http.py @@ -310,7 +310,7 @@ def __init__(self, *args, **kwargs): def setUp(self): self.client = Client(self.servers) - self.client.retry_interval = 0.1 # faster retry + self.client.retry_interval = 0.2 # faster retry def tearDown(self): self.client.close()