git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] sigchain: recover from concurrent double-pops of the same signal

From
Iian4hu <hu2008yinxiang@163.com>
Date
Oct 28, 2026, 14:47 UTC
Message-ID
<20261028144736.121433-1-hu2008yinxiang@163.com>
In-Reply-To
<3f939144-d4b3-4bc5-aaea-16422450d638@gmail.com>
Hi Phillip,

Thanks for the review. I agree with both halves of your mail, and I think the difference between the two approaches is worth spelling out.

What I sent only repairs the aftermath. It leaves the corrupted state reachable and merely turns the wedge into the normal death, so it is small and inert on the legitimate paths, but it is a band-aid and, frankly, a bit dirty: it heals a state that should never have been entered, and by the time it heals it the two threads have already run the handler's close()/unlink() cleanup concurrently.

I did first try the serializing route. My earlier attempt (https://github.com/gitgitgadget/git/pull/2262, never sent to the list) took a per-signal spinlock around the push/pop update, with the signal blocked while the lock is held. That keeps signals[sig].n and the installed disposition consistent under any interleaving, so the corrupt state cannot be constructed at all, and it also protects sigchain_push/pop called from worker threads. I dropped it because of the edges:

  - two threads can still run the handler body concurrently; the
    lock only makes the unwind atomic, it does not serialize the
    cleanup itself;
  - the POSIX corner is awkward: sigprocmask() is unspecified in a
    multithreaded process, pthread_sigmask() is not
    async-signal-safe, and taking the lock in a handler needs one
    of them;
  - a thread that dies inside the critical section leaves the lock
    held and the next delivery spins forever, trading a hang for a
    hang;
  - the Windows branch needs its own InterlockedExchange path that
    cannot be exercised in CI here.

So the question I would like your guidance on: do you consider a locked/serialized chain a complete fix for what you described, or does this have to be prevented at the thread level - block the signals when a thread is spawned, and use sigaction() for the chain? My own reading is that serializing is a complete fix for the chain state but not for the handler bodies, so if the latter is what you want, your suggestion is the way to go and the lock does not buy much beyond it.

If you prefer the thread-level fix, I am happy to build it: a git_pthread_create() wrapper that blocks SIGINT/SIGHUP/SIGTERM/ SIGQUIT around pthread_create() - leaving SIGPIPE alone, since it is a synchronous signal and blocking it in workers turns deaths into EPIPE - plus a sigaction()-based chain that masks all signals while a handler runs. I would then drop this patch, or keep it as a separate last-resort series if you think the belt and braces are worth it.

Thanks, ian4hu

Previous: Phillip WoodNext: Phillip Wood
Message 4 of 6 in “sigchain: recover from concurrent double-pops of the same signal”
  1. sigchain: recover from concurrent double-pops of the same signalIan Hu via GitGitGadget, Oct 16, 2026
  2. ian4huOct 28, 2026
  3. Phillip WoodOct 28, 2026
  4. ian4huOct 28, 2026
  5. Phillip WoodOct 28, 2026
  6. Phillip WoodOct 29, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.