Skip to content

Commit 683782b

Browse files
committed
Close stale connections before removing them from the pool
1 parent c3d28ee commit 683782b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

neo4j/io/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,13 @@ def time_remaining():
639639
while True:
640640
# try to find a free connection in pool
641641
for connection in list(connections):
642-
if connection.closed() or connection.defunct() or connection.stale():
642+
if (connection.closed() or connection.defunct()
643+
or connection.stale()):
644+
# `close` is a noop on already closed connections.
645+
# This is to make sure that the connection is gracefully
646+
# closed, e.g. if it's just marked as `stale` but still
647+
# alive.
648+
connection.close()
643649
connections.remove(connection)
644650
continue
645651
if not connection.in_use:

0 commit comments

Comments
 (0)