Skip to content

Commit 671e843

Browse files
committed
fix: HostConnectionPool._maybe_trash_connection not to lock connection
and pool Locking connection a pool can lead to a deadlock. Consider that connection.close also locks connection.
1 parent 63b1148 commit 671e843

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cassandra/pool.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,14 +1180,14 @@ def _maybe_trash_connection(self, connection):
11801180
new_connections.remove(connection)
11811181
self._connections = new_connections
11821182

1183-
with connection.lock:
1184-
if connection.in_flight == 0:
1185-
log.debug("Skipping trash and closing unused connection (%s) to %s", id(connection), self.host)
1186-
connection.close()
1187-
1188-
# skip adding it to the trash if we're already closing it
1189-
return
1190-
1183+
if did_trash:
1184+
with connection.lock:
1185+
no_pending_requests = connection.in_flight <= len(connection.orphaned_request_ids)
1186+
if no_pending_requests:
1187+
log.debug("Skipping trash and closing unused connection (%s) to %s", id(connection), self.host)
1188+
connection.close()
1189+
return
1190+
with self._lock:
11911191
self._trash.add(connection)
11921192

11931193
if did_trash:

0 commit comments

Comments
 (0)