67
67
68
68
HB_PING_TIME = 10
69
69
HB_PONG_TIME = 10
70
- POLL_TIME_BLOCKING = 5.0
71
- POLL_TIME_NON_BLOCKING = 0.01
70
+ SELECT_TIMEOUT = 5.0
72
71
TIMEOUT_TIME = 30.0
73
72
RETRY_TIME = 5.0
74
73
@@ -540,7 +539,7 @@ def run(self) -> None:
540
539
self .logger .debug ("Thread started..." )
541
540
while not self .stop .is_set ():
542
541
try :
543
- if self ._run_once (timeout = POLL_TIME_BLOCKING ) == 1 :
542
+ if self ._run_once () == 1 :
544
543
break
545
544
except Exception : # pylint: disable=broad-except
546
545
self ._force_recon = True
@@ -555,7 +554,7 @@ def run(self) -> None:
555
554
# Clean up
556
555
self ._cleanup ()
557
556
558
- def _run_once (self , timeout : float = POLL_TIME_NON_BLOCKING ) -> int :
557
+ def _run_once (self ) -> int :
559
558
"""Receive from the socket and handle data."""
560
559
# pylint: disable=too-many-branches, too-many-statements, too-many-return-statements
561
560
@@ -568,9 +567,13 @@ def _run_once(self, timeout: float = POLL_TIME_NON_BLOCKING) -> int:
568
567
# A connection has been established at this point by self._check_connection
569
568
assert self .socket is not None
570
569
571
- # poll the socket, as well as the socketpair to allow us to be interrupted
570
+ # Poll the socket and the socketpair, with a timeout of SELECT_TIMEOUT
571
+ # The timeout ensures we call _check_connection often enough to avoid
572
+ # the HeartbeatController from detecting a timeout
573
+ # The socketpair allow us to be interrupted on shutdown without waiting
574
+ # for the SELECT_TIMEOUT timout to expire
572
575
try :
573
- ready = self .selector .select (timeout )
576
+ ready = self .selector .select (SELECT_TIMEOUT )
574
577
except (ValueError , OSError ) as exc :
575
578
self .logger .error (
576
579
"[%s(%s):%s] Error in select call: %s" ,
0 commit comments