Skip to content

Commit c602082

Browse files
committed
Close urllib3 pool before swapping the server into the "inactive" list
1 parent 56f329c commit c602082

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/crate/client/http.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,14 @@ 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:
576+
pass
577+
578+
# Apply bookkeeping.
571579
try:
572580
self._active_servers.remove(server)
573581
except ValueError:
@@ -576,7 +584,7 @@ def _drop_server(self, server, message):
576584
heapq.heappush(self._inactive_servers, (time(), server, message))
577585
logger.warning("Removed server %s from active pool", server)
578586

579-
# if this is the last server raise exception, otherwise try next
587+
# If this is the last server, raise an exception.
580588
if not self._active_servers:
581589
raise ConnectionError(
582590
("No more Servers available, "

0 commit comments

Comments
 (0)