diff --git a/src/crate/client/http.py b/src/crate/client/http.py index 5642dd41..02aa80bd 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, "