Skip to content

Close urllib3 pool before swapping the server into the "inactive" list #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/crate/client/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down