2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-04 08:15:25 +00:00

jsonrpc: Treat receiving part of a message as activity.

Until now, the jsonrpc code has only counted receiving a full JSON-RPC
messages as activity.  This could theoretically time out, then, while a
very long message is in transit or if a slow link is involved.  This commit
changes this code to count receiving any part of a message as activity.

This isn't a problem for OpenFlow connections because OpenFlow messages are
at most 64 kB in size.

This problem hasn't actually been observed in practice.

Bug #12789.
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2012-09-05 13:34:35 -07:00
parent f97cae2999
commit 3a8d38c88e
3 changed files with 35 additions and 1 deletions

View File

@@ -186,6 +186,7 @@ class Connection(object):
self.input = ""
self.output = ""
self.parser = None
self.received_bytes = 0
def close(self):
self.stream.close()
@@ -221,6 +222,9 @@ class Connection(object):
else:
return len(self.output)
def get_received_bytes(self):
return self.received_bytes
def __log_msg(self, title, msg):
vlog.dbg("%s: %s %s" % (self.name, title, msg))
@@ -271,6 +275,7 @@ class Connection(object):
return EOF, None
else:
self.input += data
self.received_bytes += len(data)
else:
if self.parser is None:
self.parser = ovs.json.Parser()
@@ -444,7 +449,16 @@ class Session(object):
self.pstream = None
if self.rpc:
received_bytes = self.rpc.get_received_bytes()
self.rpc.run()
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())
error = self.rpc.get_status()
if error != 0:
self.reconnect.disconnected(ovs.timeval.msec(), error)