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, " 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()