mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +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:
@@ -178,6 +178,14 @@ jsonrpc_get_backlog(const struct jsonrpc *rpc)
|
||||
return rpc->status ? 0 : rpc->backlog;
|
||||
}
|
||||
|
||||
/* Returns the number of bytes that have been received on 'rpc''s underlying
|
||||
* stream. (The value wraps around if it exceeds UINT_MAX.) */
|
||||
unsigned int
|
||||
jsonrpc_get_received_bytes(const struct jsonrpc *rpc)
|
||||
{
|
||||
return rpc->input.head;
|
||||
}
|
||||
|
||||
/* Returns 'rpc''s name, that is, the name returned by stream_get_name() for
|
||||
* the stream underlying 'rpc' when 'rpc' was created. */
|
||||
const char *
|
||||
@@ -988,10 +996,21 @@ struct jsonrpc_msg *
|
||||
jsonrpc_session_recv(struct jsonrpc_session *s)
|
||||
{
|
||||
if (s->rpc) {
|
||||
unsigned int received_bytes;
|
||||
struct jsonrpc_msg *msg;
|
||||
|
||||
received_bytes = jsonrpc_get_received_bytes(s->rpc);
|
||||
jsonrpc_recv(s->rpc, &msg);
|
||||
if (msg) {
|
||||
if (received_bytes != jsonrpc_get_received_bytes(s->rpc)) {
|
||||
/* 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. */
|
||||
reconnect_activity(s->reconnect, time_msec());
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
if (msg->type == JSONRPC_REQUEST && !strcmp(msg->method, "echo")) {
|
||||
/* Echo request. Send reply. */
|
||||
struct jsonrpc_msg *reply;
|
||||
|
Reference in New Issue
Block a user