This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 315
Stop leaking connections when pool is full #473
Open
FranGM
wants to merge
1
commit into
Grokzen:master
Choose a base branch
from
FranGM:issue-458-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -277,7 +277,7 @@ def make_connection(self, node): | |||||||
|
||||||||
return connection | ||||||||
|
||||||||
def release(self, connection): | ||||||||
def release(self, connection, add_to_pool=True): | ||||||||
""" | ||||||||
Releases the connection back to the pool | ||||||||
""" | ||||||||
|
@@ -296,7 +296,15 @@ def release(self, connection): | |||||||
pass | ||||||||
# TODO: Log.warning("Tried to release connection that did not exist any longer : {0}".format(connection)) | ||||||||
|
||||||||
self._available_connections.setdefault(connection.node["name"], []).append(connection) | ||||||||
if add_to_pool: | ||||||||
self._available_connections.setdefault(connection.node["name"], []).append(connection) | ||||||||
else: | ||||||||
# If we don't add it back to the pool it shouldn't count towards the | ||||||||
# connection pool, or we'll artificially reduce the maximum size of the | ||||||||
# pool | ||||||||
self._created_connections_per_node.setdefault(node['name'], 0) | ||||||||
if self._created_connections_per_node[connection.node["name"]] > 0: | ||||||||
self._created_connections_per_node[connection.node["name"]] -= 1 | ||||||||
|
||||||||
def disconnect(self): | ||||||||
""" | ||||||||
|
@@ -538,17 +546,21 @@ def get_connection_by_node(self, node): | |||||||
|
||||||||
return connection | ||||||||
|
||||||||
def release(self, connection): | ||||||||
def release(self, connection, add_to_pool=True): | ||||||||
""" | ||||||||
Releases the connection back to the pool | ||||||||
""" | ||||||||
self._checkpid() | ||||||||
if connection.pid != self.pid: | ||||||||
return | ||||||||
|
||||||||
# In some cases we don't want to add back this connection to the pool but | ||||||||
# we still want to free its slot | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
conn_to_add = connection if add_to_pool else None | ||||||||
|
||||||||
# Put the connection back into the pool. | ||||||||
try: | ||||||||
self._get_pool(connection.node).put_nowait(connection) | ||||||||
self._get_pool(connection.node).put_nowait(conn_to_add) | ||||||||
except Full: | ||||||||
# perhaps the pool has been reset() after a fork? regardless, | ||||||||
# we don't want this connection | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -203,7 +203,15 @@ def _send_cluster_commands(self, stack, raise_on_error=True, allow_redirections= | |||||
# we can build a list of commands for each node. | ||||||
node_name = node['name'] | ||||||
if node_name not in nodes: | ||||||
nodes[node_name] = NodeCommands(self.parse_response, self.connection_pool.get_connection_by_node(node)) | ||||||
try: | ||||||
nodes[node_name] = NodeCommands(self.parse_response, self.connection_pool.get_connection_by_node(node)) | ||||||
except: | ||||||
# Sommething happened, maybe the pool is full, we need to release any connection | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo:
Suggested change
|
||||||
# we've taken or we'll leak them. Because we're not sure if the connections are | ||||||
# in a good state we'll release their slot but not reuse them | ||||||
for n in nodes.values(): | ||||||
self.connection_pool.release(n.connection, add_to_pool=False) | ||||||
raise | ||||||
|
||||||
nodes[node_name].append(c) | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.