Skip to content

Commit

Permalink
Cygwin: signal: Fix deadlock between main thread and sig thread
Browse files Browse the repository at this point in the history
Previously, a deadlock happened if many SIGSTOP/SIGCONT signals were
received rapidly. If the main thread sends __SIGFLUSH at the timing
when SIGSTOP is handled by the sig thread, but not is handled by the
main thread yet (sig_handle_tty_stop() not called yet), and if SIGCONT
is received, the sig thread waits for cygtls::current_sig (is SIGSTOP
now) cleared. However, the main thread waits for the pack.wakeup using
WaitForSingleObject(), so the main thread cannot handle SIGSTOP. This
is the mechanism of the deadlock. This patch uses cygwait() instead of
WaitForSingleObject() to be able to handle the pending SIGSTOP.

Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html
Fixes: 7759daa ("(sig_send): Fill out sigpacket structure to send to signal thread rather than racily sending separate packets.")
Reported-by: Christian Franke <[email protected]>
Reviewed-by: Corinna Vinschen <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
  • Loading branch information
tyan0 committed Nov 28, 2024
1 parent 522f3e9 commit d243e51
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion winsup/cygwin/sigproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
if (wait_for_completion)
{
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
rc = WaitForSingleObject (pack.wakeup, WSSC);
rc = cygwait (pack.wakeup, WSSC);
ForceCloseHandle (pack.wakeup);
}
else
Expand Down

0 comments on commit d243e51

Please sign in to comment.