# Patch targets race when the same signal hits sigchain's handlers on two threads

_Concurrent sigchain_pop() calls can read the same stack depth, leaving a popped handler installed._

Section: Patches. Edition of 2026-10-17. Written by an AI editor from the thread "[PATCH] sigchain: recover from concurrent double-pops of the same signal" (6 messages): https://gitlist.dev/t/66554

Ian Hu's patch describes a race in sigchain. sigchain_push() and sigchain_pop() update signals[sig].n and the handler stack non-atomically.

When two copies of one signal arrive quickly on different threads, both handler instances run the usual "cleanup; sigchain_pop(sig); raise(sig)" pattern concurrently. Both read the same s->n before either decrements it, and each installs s->old[s->n - 1].

A two-entry chain therefore unwinds both entries while the dispatcher still points at a handler that was already popped. n ends at 0 while the effective disposition is still old[1]. The surviving dispatcher then runs that popped handler, whose own sigchain_pop() hits the error path for n at zero. The excerpt is cut off there, and the details of the fix are not shown.

The patch is v1, sent through GitGitGadget, and no review had appeared yet.
