Skip to content

Commit 9c441bc

Browse files
committed
control-connection: reconnect after stale failure
1 parent f9f9916 commit 9c441bc

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

cassandra/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5362,10 +5362,10 @@ def _signal_error(self):
53625362
# host may be None if it's already been removed, but that indicates
53635363
# that errors have already been reported, so we're fine
53645364
if host:
5365-
self._cluster.signal_connection_failure(
5365+
if self._cluster.signal_connection_failure(
53665366
host, self._connection.last_error, is_host_addition=False,
5367-
expected_endpoint=self._connection.endpoint)
5368-
return
5367+
expected_endpoint=self._connection.endpoint):
5368+
return
53695369

53705370
# if the connection is not defunct or the host already left, reconnect
53715371
# manually

tests/unit/test_control_connection.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,34 @@ def test_stale_control_connection_failure_is_endpoint_fenced(self):
455455
host, self.connection.last_error, is_host_addition=False,
456456
expected_endpoint=old_endpoint)
457457

458+
def test_stale_control_connection_failure_reconnects_when_cluster_ignores_signal(self):
459+
host_id = uuid.uuid4()
460+
old_endpoint = ClientRoutesEndPoint(
461+
host_id, Mock(), "127.0.0.1", original_port=9042)
462+
new_endpoint = ClientRoutesEndPoint(
463+
host_id, Mock(), "127.0.0.1", original_port=9142)
464+
465+
host = Host(old_endpoint, SimpleConvictionPolicy, host_id=host_id)
466+
host.set_up()
467+
self.cluster.metadata = Metadata()
468+
self.cluster.metadata.add_or_return_host(host)
469+
host.endpoint = new_endpoint
470+
self.cluster.metadata.update_host(host, old_endpoint)
471+
472+
self.connection.endpoint = old_endpoint
473+
self.connection.is_defunct = True
474+
self.connection.last_error = ConnectionException(
475+
"stale control connection failed", endpoint=old_endpoint)
476+
self.cluster.signal_connection_failure = Mock(return_value=False)
477+
self.control_connection.reconnect = Mock()
478+
479+
self.control_connection._signal_error()
480+
481+
self.cluster.signal_connection_failure.assert_called_once_with(
482+
host, self.connection.last_error, is_host_addition=False,
483+
expected_endpoint=old_endpoint)
484+
self.control_connection.reconnect.assert_called_once_with()
485+
458486
def test_refresh_nodes_and_tokens_uses_preloaded_results_if_given(self):
459487
"""
460488
refresh_nodes_and_tokens uses preloaded results if given for shared table queries

0 commit comments

Comments
 (0)