Skip to content

Commit 8aeb926

Browse files
committed
cancel timers before defuncting connection
This allows us to revert some of the fix to PYTHON-367 without the timer heap growing out of control as described on that ticket. We cancel before defuncting to ensure that the timer doesn't hang around while running callbacks. Between this change and the delegation of callbacks to a secondary thread (see commit 5192302, part of the original PYTHON-367 fix), this commit should not cause a regression on PYTHON-367. Note that we don't cancel timers before defuncting and retrying -- we're not done with the logical request and still want that timer to fire. Now that timers are started on ResponseFuture initialization, we actually use the value of timeout in the tests, so we no longer pass that argument, allowing the test to use the default value.
1 parent 8b106c3 commit 8aeb926

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

cassandra/cluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,6 +3608,7 @@ def _set_result(self, host, connection, pool, response):
36083608
# we got some other kind of response message
36093609
msg = "Got unexpected message: %r" % (response,)
36103610
exc = ConnectionException(msg, host)
3611+
self._cancel_timer()
36113612
self._connection.defunct(exc)
36123613
self._set_final_exception(exc)
36133614
except Exception as exc:

tests/unit/test_cluster.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_default_legacy(self):
184184
self._verify_response_future_profile(rf, expected_profile)
185185

186186
def test_default_profile(self):
187-
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
187+
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
188188
cluster = Cluster(execution_profiles={'non-default': non_default_profile})
189189
session = Session(cluster, hosts=[])
190190

@@ -218,7 +218,7 @@ def test_statement_params_override_legacy(self):
218218
self._verify_response_future_profile(rf, expected_profile)
219219

220220
def test_statement_params_override_profile(self):
221-
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
221+
non_default_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
222222
cluster = Cluster(execution_profiles={'non-default': non_default_profile})
223223
session = Session(cluster, hosts=[])
224224

@@ -284,15 +284,15 @@ def test_no_legacy_with_profile(self):
284284

285285
def test_profile_name_value(self):
286286

287-
internalized_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
287+
internalized_profile = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
288288
cluster = Cluster(execution_profiles={'by-name': internalized_profile})
289289
session = Session(cluster, hosts=[])
290290
self.assertEqual(cluster._config_mode, _ConfigMode.PROFILES)
291291

292292
rf = session.execute_async("query", execution_profile='by-name')
293293
self._verify_response_future_profile(rf, internalized_profile)
294294

295-
by_value = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(5)])
295+
by_value = ExecutionProfile(RoundRobinPolicy(), *[object() for _ in range(3)])
296296
rf = session.execute_async("query", execution_profile=by_value)
297297
self._verify_response_future_profile(rf, by_value)
298298

0 commit comments

Comments
 (0)