Skip to content

Commit

Permalink
Close urllib3 pool before swapping the server into the "inactive" list
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Mar 17, 2021
1 parent d2fb2b5 commit 1081140
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/crate/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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, "
Expand Down

0 comments on commit 1081140

Please sign in to comment.