]> git.tuebingen.mpg.de Git - paraslash.git/commit
server: Fix race condition in com_stat().
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 9 Nov 2022 19:46:48 +0000 (20:46 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 25 Nov 2022 12:22:16 +0000 (13:22 +0100)
commit9b19e0b3ea712754f241dea8f1e49da6f9ac8820
treef2ee665846b192fe7e79dd206a21d03224c39325
parent10596c5a763716368579b6313953ae0861b03ad4
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.
command.c