diff --git a/daemon/main.c b/daemon/main.c index b303a7eec..016a29d46 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1342,12 +1342,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);