From 9eb7b640c2652b3efbfd3fd214d520da621023ef Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 6 Sep 2022 10:51:28 -0400 Subject: [PATCH] TT#14008 add explicit lws_cancel_service at shutdown Newer libwebsockets versions seem to use a longer internal timeout, so an explicit "interrupt" is needed during shutdown to prevent a long wait time. Change-Id: I8f28ef658169178e35b40dd44520fbd7c812b590 --- daemon/main.c | 4 +++- daemon/websocket.c | 5 +++++ include/websocket.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/daemon/main.c b/daemon/main.c index 2f7019f6e..fe630c7de 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1343,12 +1343,14 @@ int main(int argc, char **argv) { // reap threads as they shut down during run time threads_join_all(false); + service_notify("STOPPING=1\n"); + // free libevent #if LIBEVENT_VERSION_NUMBER >= 0x02010100 libevent_global_shutdown(); #endif - service_notify("STOPPING=1\n"); + websocket_stop(); if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) redis_async_event_base_action(rtpe_redis_write, EVENT_BASE_LOOPBREAK); diff --git a/daemon/websocket.c b/daemon/websocket.c index 1ac151832..1472c3d93 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -1077,3 +1077,8 @@ void websocket_start(void) { return; thread_create_detach_prio(websocket_loop, NULL, rtpe_config.scheduling, rtpe_config.priority, "websocket"); } +void websocket_stop(void) { + if (!websocket_context) + return; + lws_cancel_service(websocket_context); +} diff --git a/include/websocket.h b/include/websocket.h index 88eca60bc..57a0622fb 100644 --- a/include/websocket.h +++ b/include/websocket.h @@ -35,6 +35,7 @@ struct websocket_message { int websocket_init(void); void websocket_start(void); +void websocket_stop(void); // appends to output buffer without triggering a response void websocket_queue_raw(struct websocket_conn *wc, const char *msg, size_t len);