LP#1746577 Websocket responder exits on jabber disconnect
authorBill Erickson <berickxx@gmail.com>
Wed, 31 Jan 2018 18:07:41 +0000 (13:07 -0500)
committerJason Stephenson <jason@sigio.com>
Thu, 1 Feb 2018 20:51:09 +0000 (15:51 -0500)
Regularly check for Jabber socket disconnects in the websocket gateway
"responder" thread (that relays messages from opensrf to the WS client)
and force a client disconnect when a broken jabber socket is detected.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>

src/gateway/osrf_websocket_translator.c

index ef8d4af..f43fb62 100644 (file)
@@ -344,10 +344,26 @@ void* APR_THREAD_FUNC osrf_responder_thread_main(apr_thread_t *thread, void *dat
             return NULL;
         }
 
-        // wait for a response
+        // wait indefinitely for a response
         tmsg = client_recv(osrf_handle, -1);
 
-        if (!tmsg) continue; // interrupt
+        if (!tmsg) {
+            // tmsg can only be NULL if the underlying select() call is
+            // interrupted or the jabber socket connection was severed.
+
+            if (client_connected(osrf_handle) &&
+                socket_connected(osrf_handle->session->sock_id)) {
+                continue; // interrupted.  restart loop.
+            }
+
+            // Socket connection was broken.  Send disconnect to client,
+            // causing on_disconnect_handler to run and cleanup.
+            osrfLogWarning(OSRF_LOG_MARK, 
+                "WS: Jabber socket disconnected. Sending close() to client");
+
+            trans->server->close(trans->server);
+            return NULL; // exit thread
+        }
 
         if (trans->client_connected) {