jsonrpc: Properly implement connection timeout.
authorBen Pfaff <blp@nicira.com>
Fri, 8 Jan 2010 23:36:06 +0000 (15:36 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 8 Jan 2010 23:36:06 +0000 (15:36 -0800)
jsonrpc_session_connect() indirectly called reconnect_disconnected(), which
told the reconnect object that the connection had failed, before it told it
that the connection attempt had started.  When the connection didn't
complete immediately, this caused the connection to time out immediately,
without any backoff.

Reported by Jeremy Stribling.

lib/jsonrpc.c

index f42035e80f5884e7cf25aeca0a730dea391f4c27..aeb1dd8245fa77b14562b986472ab55fc1d1ea4a 100644 (file)
@@ -686,7 +686,6 @@ jsonrpc_session_close(struct jsonrpc_session *s)
 static void
 jsonrpc_session_disconnect(struct jsonrpc_session *s)
 {
-    reconnect_disconnected(s->reconnect, time_msec(), 0);
     if (s->rpc) {
         jsonrpc_error(s->rpc, EOF);
         jsonrpc_close(s->rpc);
@@ -723,6 +722,7 @@ jsonrpc_session_run(struct jsonrpc_session *s)
         jsonrpc_run(s->rpc);
         error = jsonrpc_get_status(s->rpc);
         if (error) {
+            reconnect_disconnected(s->reconnect, time_msec(), 0);
             jsonrpc_session_disconnect(s);
         }
     } else if (s->stream) {
@@ -747,6 +747,7 @@ jsonrpc_session_run(struct jsonrpc_session *s)
         break;
 
     case RECONNECT_DISCONNECT:
+        reconnect_disconnected(s->reconnect, time_msec(), 0);
         jsonrpc_session_disconnect(s);
         break;