From: Andre Noll Date: Wed, 9 Nov 2022 19:46:48 +0000 (+0100) Subject: server: Fix race condition in com_stat(). X-Git-Tag: v0.7.2~12^2 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=9b19e0b3ea712754f241dea8f1e49da6f9ac8820 server: Fix race condition in com_stat(). We need to block not only SIGTERM but also SIGUSR1 in the command handler of the stat server command because otherwise the signal is lost if it arrives within a small race window. If this happens, the next status update will be up to 50 seconds late. The race condition is even explained in the comment nearby... The bug was observed in a situation where the last admissible file of the current mood became inadmissible, causing the server to stop streaming. This is reflected by the status flags transition from P (playing) to N (stopped) via the intermediate state PN (trying to load next file). After either transition the server process sends SIGUSR1 to the command handler. If the second signal arrives just after the PN state was sampled but before the command handler goes to sleep by calling pselect(2), the signal handler runs and sets subcmd_should_die, but this won't be acted upon until after we sleep for up to 50 seconds in pselect(2). As a result, para_audiod, hence para_gui, keep reporting the stale PN state during this period. This bug was present in the code base since day one of the git repo in 2006. --- diff --git a/command.c b/command.c index 0c483bef..427c90fe 100644 --- a/command.c +++ b/command.c @@ -514,6 +514,7 @@ static int com_stat(struct command_context *cc, struct lls_parse_result *lpr) * while we sleep. */ para_block_signal(SIGTERM); + para_block_signal(SIGUSR1); for (;;) { sigset_t set; /*