Skip to content

Commit ee5586c

Browse files
committed
cluster: split timeout host endpoint handling
1 parent 3752468 commit ee5586c

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

cassandra/cluster.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,7 +4601,13 @@ def _on_timeout(self, _attempts=0):
46014601
errors = self._errors
46024602
if not errors:
46034603
if self.is_schema_agreed:
4604-
key = str(self._get_host_endpoint(self._current_host)) if self._current_host else 'no host queried before timeout'
4604+
if self._current_host is None:
4605+
key = 'no host queried before timeout'
4606+
elif self._connection is not None and self._connection.is_control_connection:
4607+
control_host = self.session.cluster.get_control_connection_host()
4608+
key = str(control_host.endpoint) if control_host is not None else str(self._connection.endpoint)
4609+
else:
4610+
key = str(self._current_host.endpoint)
46054611
errors = {key: "Client request timeout. See Session.execute[_async](timeout)"}
46064612
else:
46074613
connection = self.session.cluster.control_connection._connection
@@ -4669,10 +4675,6 @@ def send_request(self, error_no_hosts=True):
46694675
"Unable to complete the operation against any hosts", self._errors))
46704676
return False
46714677

4672-
@staticmethod
4673-
def _get_host_endpoint(host):
4674-
return getattr(host, 'endpoint', host)
4675-
46764678
def _has_usable_node_pool(self):
46774679
try:
46784680
pools = tuple(self.session._pools.values())

tests/unit/test_response_future.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,32 @@ def send_msg(message, request_id, cb, **kwargs):
644644
with pytest.raises(OperationTimedOut):
645645
rf.result()
646646

647+
def test_control_connection_fallback_timeout_without_metadata_host_uses_connection_endpoint(self):
648+
session = self.make_basic_session()
649+
session.cluster.allow_control_connection_query_fallback = ControlConnectionQueryFallback.Fallback
650+
session.cluster._default_load_balancing_policy.make_query_plan.return_value = ['ip1']
651+
session._pools = {}
652+
session.cluster.get_control_connection_host.return_value = None
653+
connection = self.make_control_connection()
654+
session.cluster.control_connection._connection = connection
655+
656+
def send_msg(message, request_id, cb, **kwargs):
657+
connection._requests[request_id] = (cb, kwargs.get('decoder'), kwargs.get('result_metadata'))
658+
return 128
659+
660+
connection.send_msg.side_effect = send_msg
661+
662+
rf = self.make_response_future(session)
663+
rf.send_request()
664+
rf._on_timeout()
665+
666+
with pytest.raises(OperationTimedOut) as exc_info:
667+
rf.result()
668+
669+
assert exc_info.value.errors == {
670+
'control-host': 'Client request timeout. See Session.execute[_async](timeout)'
671+
}
672+
647673
def test_first_pool_shutdown(self):
648674
session = self.make_basic_session()
649675
session.cluster._default_load_balancing_policy.make_query_plan.return_value = ['ip1', 'ip2']

0 commit comments

Comments
 (0)