Skip to content

Commit 0e6e37b

Browse files
Lorak-mmkfruch
authored andcommitted
Fix 'USE ks' race condition
1 parent 07bd1d8 commit 0e6e37b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

cassandra/pool.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ def _open_connection_to_missing_shard(self, shard_id):
739739
conn.shard_id,
740740
self.host
741741
)
742+
if self._keyspace:
743+
conn.set_keyspace_blocking(self._keyspace)
744+
742745
self._connections[conn.shard_id] = conn
743746
if old_conn is not None:
744747
remaining = old_conn.in_flight - len(old_conn.orphaned_request_ids)
@@ -763,13 +766,6 @@ def _open_connection_to_missing_shard(self, shard_id):
763766
old_conn.close()
764767
else:
765768
self._trash.add(old_conn)
766-
if self._keyspace:
767-
with self._lock:
768-
if self.is_shutdown:
769-
conn.close()
770-
old_conn = self._connections.get(conn.shard_id)
771-
if old_conn:
772-
old_conn.set_keyspace_blocking(self._keyspace)
773769
num_missing_or_needing_replacement = self.num_missing_or_needing_replacement
774770
log.debug(
775771
"Connected to %s/%i shards on host %s (%i missing or needs replacement)",

0 commit comments

Comments
 (0)