Ian Hu (ian4hu) reports that sigchain_push() and sigchain_pop() update the handler stack non-atomically. If two copies of the same signal reach different threads in quick succession, both handlers run the usual "cleanup; sigchain_pop(sig); raise(sig)" pattern and read the same s->n before either decrements it. The chain then unwinds two entries instead of one, and the process can end up spinning in a handler that keeps re-raising the signal. He says this is reachable with "git clone --depth 1" over ssh receiving two SIGTERMs in quick succession, and that only SIGKILL stops the process.
The patch leaves the push/pop fast path alone. It changes the "n < 1" guard in sigchain_pop() so that it falls back to the pre-chain disposition instead of wedging. It is queued in 'seen' as iy/sigchain-recover-concurrent-pops and marked "Needs review" in the latest What's cooking.
Phillip Wood said the bug looks like the same chain of signal handlers being unwound in two threads at once, which could mean the same handler is called twice. He suggested ensuring signals are blocked when a new thread is spawned, so that they are handled in a single thread, and using sigaction() so that a handler is not interrupted by another instance of the same signal. He noted this would not help for threads created by external libraries, and that he would wait for others to comment before investing much time.
Ian Hu agreed with both halves of Wood's reply. He called his patch a band-aid that only repairs the aftermath and leaves the corrupted state reachable, and said the two threads have already run the cleanup concurrently by the time it heals. He mentioned an earlier serializing attempt that was never sent to the list. The question of which approach to take remains open.