@@ -109,19 +109,19 @@ def __init__(self, hosts, connection_func, socket_handling):
109
109
110
110
def __iter__ (self ):
111
111
if not self .last_attempt :
112
- self .last_attempt = time .time ()
112
+ self .last_attempt = time .monotonic ()
113
113
delay = 0.5
114
114
while True :
115
115
yield self ._next_server (delay )
116
116
117
117
def _next_server (self , delay ):
118
118
jitter = random .randint (0 , 100 ) / 100.0
119
- while time .time () < self .last_attempt + delay + jitter :
119
+ while time .monotonic () < self .last_attempt + delay + jitter :
120
120
# Skip rw ping checks if its too soon
121
121
return False
122
122
for host , port in self .hosts :
123
123
log .debug ("Pinging server for r/w: %s:%s" , host , port )
124
- self .last_attempt = time .time ()
124
+ self .last_attempt = time .monotonic ()
125
125
try :
126
126
with self .socket_handling ():
127
127
sock = self .connection ((host , port ))
@@ -136,7 +136,7 @@ def _next_server(self, delay):
136
136
return False
137
137
138
138
# Add some jitter between host pings
139
- while time .time () < self .last_attempt + jitter :
139
+ while time .monotonic () < self .last_attempt + jitter :
140
140
return False
141
141
delay *= 2
142
142
@@ -617,14 +617,14 @@ def _connect_attempt(self, host, hostip, port, retry):
617
617
connect_timeout = connect_timeout / 1000.0
618
618
retry .reset ()
619
619
self .ping_outstanding .clear ()
620
- last_send = time .time ()
620
+ last_send = time .monotonic ()
621
621
with self ._socket_error_handling ():
622
622
while not self .client ._stopped .is_set ():
623
623
# Watch for something to read or send
624
624
jitter_time = random .randint (1 , 40 ) / 100.0
625
625
deadline = last_send + read_timeout / 2.0 - jitter_time
626
626
# Ensure our timeout is positive
627
- timeout = max ([deadline - time .time (), jitter_time ])
627
+ timeout = max ([deadline - time .monotonic (), jitter_time ])
628
628
s = self .handler .select (
629
629
[self ._socket , self ._read_sock ], [], [], timeout
630
630
)[0 ]
@@ -646,12 +646,12 @@ def _connect_attempt(self, host, hostip, port, retry):
646
646
if self ._read_sock in s :
647
647
self ._send_request (read_timeout , connect_timeout )
648
648
# Requests act as implicit pings.
649
- last_send = time .time ()
649
+ last_send = time .monotonic ()
650
650
continue
651
651
652
- if time .time () >= deadline :
652
+ if time .monotonic () >= deadline :
653
653
self ._send_ping (connect_timeout )
654
- last_send = time .time ()
654
+ last_send = time .monotonic ()
655
655
self .logger .info ("Closing connection to %s:%s" , host , port )
656
656
client ._session_callback (KeeperState .CLOSED )
657
657
return STOP_CONNECTING
0 commit comments