Skip to content

Commit 4e2e9bb

Browse files
committed
HearbeatFuture: Use correct timeout in error message
The timeout argument in `wait` tells how much we need to wait taking into consideration that we already waited for some other futures. The total wait time that this future had available to complete is different: it includes time we spent waiting for other futures. This created confusing hearbeat messages, that could even show negative wait times. I fixed it by putting both timeouts in the error message. The `timeout` parameter of `OperationTimedOut` I changed to the original timeout because I think it is more useful and relevant here.
1 parent 7fb09eb commit 4e2e9bb

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

cassandra/connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,15 +1821,15 @@ def __init__(self, connection, owner):
18211821
self._exception = Exception("Failed to send heartbeat because connection 'in_flight' exceeds threshold")
18221822
self._event.set()
18231823

1824-
def wait(self, timeout):
1824+
def wait(self, timeout, original_timeout):
18251825
self._event.wait(timeout)
18261826
if self._event.is_set():
18271827
if self._exception:
18281828
raise self._exception
18291829
else:
1830-
raise OperationTimedOut("Connection heartbeat timeout after %s seconds" % (timeout,),
1830+
raise OperationTimedOut("Connection heartbeat timeout (total wait=%s seconds, this wait call=%s seconds)" % (original_timeout, timeout),
18311831
self.connection.endpoint,
1832-
timeout=timeout,
1832+
timeout=original_timeout,
18331833
in_flight=self.connection.in_flight)
18341834

18351835
def _options_callback(self, response):
@@ -1894,7 +1894,7 @@ def run(self):
18941894
self._raise_if_stopped()
18951895
connection = f.connection
18961896
try:
1897-
f.wait(timeout_left)
1897+
f.wait(timeout_left, self._timeout)
18981898
# TODO: move this, along with connection locks in pool, down into Connection
18991899
with connection.lock:
19001900
connection.in_flight -= 1

tests/unit/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def send_msg(msg, req_id, msg_callback):
518518
connection.defunct.assert_has_calls([call(ANY)] * get_holders.call_count)
519519
exc = connection.defunct.call_args_list[0][0][0]
520520
assert isinstance(exc, OperationTimedOut)
521-
assert exc.errors == 'Connection heartbeat timeout after 0.05 seconds'
521+
assert exc.errors == 'Connection heartbeat timeout (total wait=0.05 seconds, this wait call=0.05 seconds)'
522522
assert exc.last_host == DefaultEndPoint('localhost')
523523
assert exc.timeout == 0.05
524524
assert isinstance(exc.in_flight, int)

0 commit comments

Comments
 (0)