Skip to content

Commit 66dd315

Browse files
committed
Merged PYTHON-793
2 parents d3e9601 + 86a88c3 commit 66dd315

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Bug Fixes
1212
* Not create two sessions by default in CQLEngine (PYTHON-814)
1313
* Bug when subclassing AyncoreConnection (PYTHON-827)
1414
* Error at cleanup when closing the asyncore connections (PYTHON-829)
15+
* Fix sites where `sessions` can change during iteration (PYTHON-793)
1516

1617
3.11.0
1718
======
@@ -35,6 +36,7 @@ Bug Fixes
3536
* Ensure unused connections are closed if a Session is deleted by the GC (PYTHON-774)
3637
* Fix .values_list by using db names internally (cqlengine) (PYTHON-785)
3738

39+
3840
Other
3941
-----
4042
* Bump Cython dependency version to 0.25.2 (PYTHON-754)

cassandra/cluster.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def __init__(self, street, zipcode):
964964
"be returned when reading type %s.%s.", self.protocol_version, keyspace, user_type)
965965

966966
self._user_types[keyspace][user_type] = klass
967-
for session in self.sessions:
967+
for session in tuple(self.sessions):
968968
session.user_type_registered(keyspace, user_type, klass)
969969
UserType.evict_udt_class(keyspace, user_type)
970970

@@ -994,7 +994,7 @@ def add_execution_profile(self, name, profile, pool_wait_timeout=5):
994994
for host in filter(lambda h: h.is_up, self.metadata.all_hosts()):
995995
profile.load_balancing_policy.on_up(host)
996996
futures = set()
997-
for session in self.sessions:
997+
for session in tuple(self.sessions):
998998
futures.update(session.update_created_pools())
999999
_, not_done = wait_futures(futures, pool_wait_timeout)
10001000
if not_done:
@@ -1212,7 +1212,7 @@ def connect(self, keyspace=None, wait_for_all_pools=False):
12121212

12131213
def get_connection_holders(self):
12141214
holders = []
1215-
for s in self.sessions:
1215+
for s in tuple(self.sessions):
12161216
holders.extend(s.get_pools())
12171217
holders.append(self.control_connection)
12181218
return holders
@@ -1238,7 +1238,7 @@ def shutdown(self):
12381238

12391239
self.control_connection.shutdown()
12401240

1241-
for session in self.sessions:
1241+
for session in tuple(self.sessions):
12421242
session.shutdown()
12431243

12441244
self.executor.shutdown()
@@ -1265,7 +1265,7 @@ def _session_register_user_types(self, session):
12651265
def _cleanup_failed_on_up_handling(self, host):
12661266
self.profile_manager.on_down(host)
12671267
self.control_connection.on_down(host)
1268-
for session in self.sessions:
1268+
for session in tuple(self.sessions):
12691269
session.remove_pool(host)
12701270

12711271
self._start_reconnector(host, is_host_addition=False)
@@ -1304,7 +1304,7 @@ def _on_up_future_completed(self, host, futures, results, lock, finished_future)
13041304
host._currently_handling_node_up = False
13051305

13061306
# see if there are any pools to add or remove now that the host is marked up
1307-
for session in self.sessions:
1307+
for session in tuple(self.sessions):
13081308
session.update_created_pools()
13091309

13101310
def on_up(self, host):
@@ -1341,7 +1341,7 @@ def on_up(self, host):
13411341
self._prepare_all_queries(host)
13421342
log.debug("Done preparing all queries for host %s, ", host)
13431343

1344-
for session in self.sessions:
1344+
for session in tuple(self.sessions):
13451345
session.remove_pool(host)
13461346

13471347
log.debug("Signalling to load balancing policies that host %s is up", host)
@@ -1354,7 +1354,7 @@ def on_up(self, host):
13541354
futures_lock = Lock()
13551355
futures_results = []
13561356
callback = partial(self._on_up_future_completed, host, futures, futures_results, futures_lock)
1357-
for session in self.sessions:
1357+
for session in tuple(self.sessions):
13581358
future = session.add_or_renew_pool(host, is_host_addition=False)
13591359
if future is not None:
13601360
have_future = True
@@ -1418,7 +1418,7 @@ def on_down(self, host, is_host_addition, expect_host_to_be_down=False):
14181418
# this is to avoid closing pools when a control connection host became isolated
14191419
if self._discount_down_events and self.profile_manager.distance(host) != HostDistance.IGNORED:
14201420
connected = False
1421-
for session in self.sessions:
1421+
for session in tuple(self.sessions):
14221422
pool_states = session.get_pool_state()
14231423
pool_state = pool_states.get(host)
14241424
if pool_state:
@@ -1434,7 +1434,7 @@ def on_down(self, host, is_host_addition, expect_host_to_be_down=False):
14341434

14351435
self.profile_manager.on_down(host)
14361436
self.control_connection.on_down(host)
1437-
for session in self.sessions:
1437+
for session in tuple(self.sessions):
14381438
session.on_down(host)
14391439

14401440
for listener in self.listeners:
@@ -1491,7 +1491,7 @@ def future_completed(future):
14911491
self._finalize_add(host)
14921492

14931493
have_future = False
1494-
for session in self.sessions:
1494+
for session in tuple(self.sessions):
14951495
future = session.add_or_renew_pool(host, is_host_addition=True)
14961496
if future is not None:
14971497
have_future = True
@@ -1509,7 +1509,7 @@ def _finalize_add(self, host, set_up=True):
15091509
listener.on_add(host)
15101510

15111511
# see if there are any pools to add or remove now that the host is marked up
1512-
for session in self.sessions:
1512+
for session in tuple(self.sessions):
15131513
session.update_created_pools()
15141514

15151515
def on_remove(self, host):
@@ -1519,7 +1519,7 @@ def on_remove(self, host):
15191519
log.debug("Removing host %s", host)
15201520
host.set_down()
15211521
self.profile_manager.on_remove(host)
1522-
for session in self.sessions:
1522+
for session in tuple(self.sessions):
15231523
session.on_remove(host)
15241524
for listener in self.listeners:
15251525
listener.on_remove(host)
@@ -1579,7 +1579,7 @@ def _ensure_core_connections(self):
15791579
If any host has fewer than the configured number of core connections
15801580
open, attempt to open connections until that number is met.
15811581
"""
1582-
for session in self.sessions:
1582+
for session in tuple(self.sessions):
15831583
for pool in tuple(session._pools.values()):
15841584
pool.ensure_core_connections()
15851585

0 commit comments

Comments
 (0)