Skip to content

Commit 464b2d3

Browse files
authored
Pretty print cluster connect timeout in logs (#405)
* Pretty print cluster connect timeout in logs Before this change, we were logging the cluster connect timeout as it is. Its default value is equal to `sys.maxsize`, so the logs were like ``` ... cluster connect timeout: 92233720368547758067s ... ``` We now output `INFINITE` for the default value. ``` ... cluster connect timeout: INFINITE ``` If the user provides a different value, it will be printed as it is now. * use float('inf') instead of sys.maxsize for the cluster connect timeout * use float formatting in logs
1 parent a4b1787 commit 464b2d3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

hazelcast/connection.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
import random
44
import struct
5-
import sys
65
import threading
76
import time
87
import uuid
@@ -33,6 +32,8 @@
3332

3433
_logger = logging.getLogger(__name__)
3534

35+
_INF = float("inf")
36+
3637

3738
class _WaitStrategy(object):
3839
def __init__(self, initial_backoff, max_backoff, multiplier, cluster_connect_timeout, jitter):
@@ -45,6 +46,11 @@ def __init__(self, initial_backoff, max_backoff, multiplier, cluster_connect_tim
4546
self._cluster_connect_attempt_begin = None
4647
self._current_backoff = None
4748

49+
if cluster_connect_timeout == _INF:
50+
self._cluster_connect_timeout_text = "INFINITE"
51+
else:
52+
self._cluster_connect_timeout_text = "%.2fs" % self._cluster_connect_timeout
53+
4854
def reset(self):
4955
self._attempt = 0
5056
self._cluster_connect_attempt_begin = time.time()
@@ -55,9 +61,9 @@ def sleep(self):
5561
time_passed = time.time() - self._cluster_connect_attempt_begin
5662
if time_passed > self._cluster_connect_timeout:
5763
_logger.warning(
58-
"Unable to get live cluster connection, cluster connect timeout (%ds) is reached. "
64+
"Unable to get live cluster connection, cluster connect timeout (%s) is reached. "
5965
"Attempt %d.",
60-
self._cluster_connect_timeout,
66+
self._cluster_connect_timeout_text,
6167
self._attempt,
6268
)
6369
return False
@@ -69,10 +75,10 @@ def sleep(self):
6975
sleep_time = min(sleep_time, self._cluster_connect_timeout - time_passed)
7076
_logger.warning(
7177
"Unable to get live cluster connection, retry in %.2fs, attempt: %d, "
72-
"cluster connect timeout: %ds, max backoff: %ds",
78+
"cluster connect timeout: %s, max backoff: %.2fs",
7379
sleep_time,
7480
self._attempt,
75-
self._cluster_connect_timeout,
81+
self._cluster_connect_timeout_text,
7682
self._max_backoff,
7783
)
7884
time.sleep(sleep_time)
@@ -315,7 +321,7 @@ def _init_wait_strategy(self, config):
315321
# If the no timeout is specified by the
316322
# user, or set to -1 explicitly, set
317323
# the timeout to infinite.
318-
cluster_connect_timeout = sys.maxsize
324+
cluster_connect_timeout = _INF
319325

320326
return _WaitStrategy(
321327
config.retry_initial_backoff,

0 commit comments

Comments
 (0)