2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

reconnect: Add Python implementation of received_attempt(), and test.

This follows up on commit 4241d652e4 ("jsonrpc: Avoid disconnecting
prematurely due to long poll intervals."), which implemented the same
thing in C.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Requested-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Ben Pfaff
2020-12-21 16:21:00 -08:00
parent 98b1d633c4
commit fcf281b0b6
5 changed files with 85 additions and 11 deletions

View File

@@ -570,13 +570,16 @@ class Session(object):
if self.rpc is not None:
received_bytes = self.rpc.get_received_bytes()
error, msg = self.rpc.recv()
now = ovs.timeval.msec()
self.reconnect.receive_attempted(now)
if received_bytes != self.rpc.get_received_bytes():
# Data was successfully received.
#
# Previously we only counted receiving a full message as
# activity, but with large messages or a slow connection that
# policy could time out the session mid-message.
self.reconnect.activity(ovs.timeval.msec())
self.reconnect.activity(now)
if not error:
if msg.type == Message.T_REQUEST and msg.method == "echo":

View File

@@ -95,7 +95,10 @@ class Reconnect(object):
def deadline(fsm):
if fsm.probe_interval:
base = max(fsm.last_activity, fsm.state_entered)
return base + fsm.probe_interval
expiration = base + fsm.probe_interval
if (fsm.last_receive_attempt is None or
fsm.last_receive_attempt >= expiration):
return expiration
return None
@staticmethod
@@ -113,7 +116,10 @@ class Reconnect(object):
@staticmethod
def deadline(fsm):
if fsm.probe_interval:
return fsm.state_entered + fsm.probe_interval
expiration = fsm.state_entered + fsm.probe_interval
if (fsm.last_receive_attempt is None or
fsm.last_receive_attempt >= expiration):
return expiration
return None
@staticmethod
@@ -153,6 +159,7 @@ class Reconnect(object):
self.last_activity = now
self.last_connected = None
self.last_disconnected = None
self.last_receive_attempt = now
self.max_tries = None
self.backoff_free_tries = 0
@@ -472,6 +479,16 @@ class Reconnect(object):
self._transition(now, Reconnect.Active)
self.last_activity = now
def receive_attempted(self, now):
"""Tell 'fsm' that some attempt to receive data on the connection was
made at 'now'. The FSM only allows probe interval timer to expire when
some attempt to receive data on the connection was received after the
time when it should have expired. This helps in the case where there's
a long delay in the poll loop and then reconnect_run() executes before
the code to try to receive anything from the remote runs. (To disable
this feature, pass None for 'now'.)"""
self.last_receive_attempt = now
def _transition(self, now, state):
if self.state == Reconnect.ConnectInProgress:
self.n_attempted_connections += 1