From ddb9396743072f97628fab168ef7fcd45a597b03 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 8 Dec 2021 23:20:17 +0100 Subject: [PATCH] Interrupt and close sockets on server stop The sockets were never interrupted or closed by the client since recent changes to run the server from a dedicated thread (see commit 04267085441d6fcd05eff7df0118708f7622e237). As a side effect, the server could never terminate properly (it was waiting on socket blocking calls), so it was always killed by the client after the WATCHDOG_DELAY. Interrupt the sockets on stop to give the servera chance to terminate property, then close them. --- app/src/server.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/server.c b/app/src/server.c index 8453f959..e89a6f10 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -763,6 +763,17 @@ run_server(void *data) { } sc_mutex_unlock(&server->mutex); + // Interrupt sockets to wake up socket blocking calls on the server + assert(server->video_socket != SC_SOCKET_NONE); + net_interrupt(server->video_socket); + net_close(server->video_socket); + + if (server->control_socket != SC_SOCKET_NONE) { + // There is no control_socket if --no-control is set + net_interrupt(server->control_socket); + net_close(server->control_socket); + } + // Give some delay for the server to terminate properly #define WATCHDOG_DELAY SC_TICK_FROM_SEC(1) sc_tick deadline = sc_tick_now() + WATCHDOG_DELAY;