From: Bill Erickson Date: Wed, 31 Jan 2018 18:07:41 +0000 (-0500) Subject: LP#1746577 Websocket responder exits on jabber disconnect X-Git-Tag: osrf_rel_3_1_1~49 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=50a6bcad0b6d94e8edd15ee460b84466bc55c941;p=OpenSRF.git LP#1746577 Websocket responder exits on jabber disconnect 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 Signed-off-by: Chris Sharp Signed-off-by: Jason Stephenson --- diff --git a/src/gateway/osrf_websocket_translator.c b/src/gateway/osrf_websocket_translator.c index ef8d4af..f43fb62 100644 --- a/src/gateway/osrf_websocket_translator.c +++ b/src/gateway/osrf_websocket_translator.c @@ -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) {