From 9b280e35186a3f0078a39ca013454cc8d0c21d62 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sat, 2 Jul 2022 15:41:06 +0300 Subject: polaris/protocol: ping improvements --- src/polaris/protocol.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/polaris') diff --git a/src/polaris/protocol.py b/src/polaris/protocol.py index a86ed84..d562ff9 100644 --- a/src/polaris/protocol.py +++ b/src/polaris/protocol.py @@ -1011,13 +1011,15 @@ class UDPConnection(threading.Thread, ConnectionStatusListener): self._logger.error(f'{lpfx} rm path: removing from outgoing_queue raised an exception: {str(exc)}') # ping pong - if self.outgoing_time_1st != 0 and self.status == ConnectionStatus.CONNECTED: + if not message and self.outgoing_time_1st != 0 and self.status == ConnectionStatus.CONNECTED: now = time.time() out_delta = now - self.outgoing_time in_delta = now - self.incoming_time - if not message and max(out_delta, in_delta) > PING_FREQUENCY: + if max(out_delta, in_delta) > PING_FREQUENCY: self._logger.debug(f'{lpfx} no activity: in for {in_delta:.2f}s, out for {out_delta:.2f}s, time to ping the damn thing') message = WrappedMessage(PingMessage(), ack=True) + # add it to outgoing_queue in order to be aggressively resent in future (if needed) + self.outgoing_queue.insert(0, message) return message -- cgit v1.2.3