Skip to content

Close stale connections before removing them from the pool #546

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 1 commit into from
May 31, 2021
Merged
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
8 changes: 7 additions & 1 deletion neo4j/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,13 @@ def time_remaining():
while True:
# try to find a free connection in pool
for connection in list(connections):
if connection.closed() or connection.defunct() or connection.stale():
if (connection.closed() or connection.defunct()
or connection.stale()):
# `close` is a noop on already closed connections.
# This is to make sure that the connection is gracefully
# closed, e.g. if it's just marked as `stale` but still
# alive.
connection.close()
connections.remove(connection)
continue
if not connection.in_use:
Expand Down