Skip to content

Commit 1081140

Browse files
committed
Close urllib3 pool before swapping the server into the "inactive" list
1 parent d2fb2b5 commit 1081140

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/crate/client/http.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,15 @@ def _drop_server(self, server, message):
568568
"""
569569
Drop server from active list and adds it to the inactive ones.
570570
"""
571+
572+
# Try to close resource first.
573+
try:
574+
self.server_pool[server].close()
575+
except Exception as ex:
576+
logger.warning("When removing server from active pool, "
577+
"resource could not be closed: %s", ex)
578+
579+
# Apply bookkeeping.
571580
try:
572581
self._active_servers.remove(server)
573582
except ValueError:
@@ -576,7 +585,7 @@ def _drop_server(self, server, message):
576585
heapq.heappush(self._inactive_servers, (time(), server, message))
577586
logger.warning("Removed server %s from active pool", server)
578587

579-
# if this is the last server raise exception, otherwise try next
588+
# If this is the last server, raise an exception.
580589
if not self._active_servers:
581590
raise ConnectionError(
582591
("No more Servers available, "

0 commit comments

Comments
 (0)