{"thread":{"id":"66704","subject":"Re: [PATCH] sigchain: recover from concurrent double-pops of the same signal","startedAt":"2026-10-29T14:15:21Z","lastAt":"2026-10-31T14:50:36Z","messageCount":4,"participants":["ian4hu","Phillip Wood","Oswald Buddenhagen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"556787","messageId":"20261029141521.164544-1-hu2008yinxiang@163.com","threadId":"66704","inReplyTo":null,"subject":"Re: [PATCH] sigchain: recover from concurrent double-pops of the same signal","fromName":"ian4hu","fromEmail":"hu2008yinxiang@163.com","sentAt":"2026-10-29T14:15:21Z","receivedAt":"2026-10-29T14:15:21Z","isPatch":true,"sender":{"key":"hu2008yinxiang@163.com","avatar":null},"body":"Hi Phillip,\n\nThanks for the follow-up.  All three points make sense; let me\nconfirm what I plan to do so we are on the same page.\n\nOn SIGPIPE: you are right that my wording was wrong.  Blocking is\nnot ignoring, and the write() fails with EPIPE either way.  What\nchanges is that the signal is not delivered while it is blocked;\nand since a SIGPIPE raised by a write is thread-directed, it stays\npending on the writing thread instead of being picked up by the\nmain thread.  If that thread never unblocks it, it is never\ndelivered, so a worker that blocks SIGPIPE simply stops dying of\nit.  I left SIGPIPE out precisely to keep the \"upstream of a pipe\ndies of SIGPIPE\" behaviour that common-init.c restores.  The set I\nplan to block is SIGINT, SIGHUP, SIGTERM and SIGQUIT.  If you\nthink SIGPIPE belongs in it too, I will add it.\n\nOn the blocking pattern: agreed.  I will block once around the\nspawn loop and restore before the join loop, rather than around\neach pthread_create(), via a small guard pair\n\n    struct signal_mask_guard guard;\n\n    block_sigchain_signals(&guard);\n    for (i = 0; i < nr_threads; i++)\n        pthread_create(&t[i], NULL, fn, &data[i]);\n    restore_sigchain_signals(&guard);\n\nplus a git_pthread_create() wrapper on top for the single-thread\ncall sites.  The loops I have in mind are preload_index(),\nindex-pack, pack-objects, grep, name-hash and the read-cache entry\nloader; the fsmonitor--daemon and simple-ipc threads I would leave\nalone for now, as they have their own lifecycle and signal\nhandling.\n\nOn sigaction: agreed as well.  The handled signal is deferred by\ndefault, so the remaining hole is a handler being interrupted by\none of the other common signals that share the same handler.  I\nwill set sa_mask to sigfillset() and save/restore the whole\nstruct sigaction, so pop() does not clobber the caller's\nsa_flags/sa_mask.\n\nThe one gap I cannot close is a thread created by library code\nrather than by us.  libcurl's threaded resolver is the case I am\naware of, depending on how libcurl is built; I do not know of an\nin-tree instance, and I will mention it in the cover letter rather\nthan claim it is covered.\n\nSo I will drop this patch and build the series along those lines.\nAs you suggested, I will wait a few days for Peff and Junio to\ncomment before spending much time on it; if nobody objects I will\nsend the replacement as v2.\n\nThanks,\nian4hu\n\n\n"},{"id":"556798","messageId":"4c2728ca-5511-4c30-a2ef-6c32fe7a3e9e@gmail.com","threadId":"66704","inReplyTo":"20261029141521.164544-1-hu2008yinxiang@163.com","subject":"Re: [PATCH] sigchain: recover from concurrent double-pops of the same signal","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-29T16:03:18Z","receivedAt":"2026-10-29T16:03:18Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 29/10/2026 14:15, ian4hu wrote:\n>\n> I left SIGPIPE out precisely to keep the \"upstream of a pipe\n> dies of SIGPIPE\" behaviour that common-init.c restores.  The set I\n> plan to block is SIGINT, SIGHUP, SIGTERM and SIGQUIT.  If you\n> think SIGPIPE belongs in it too, I will add it.\n\nI think we want to block all signals when we create a thread, so that all signals are handled by the main (initial) thread.\n\nEverything else sounds good\n\nThanks\n\nPhillip\n> On the blocking pattern: agreed.  I will block once around the\n> spawn loop and restore before the join loop, rather than around\n> each pthread_create(), via a small guard pair\n> >      struct signal_mask_guard guard;\n> >      block_sigchain_signals(&guard);\n>      for (i = 0; i < nr_threads; i++)\n>          pthread_create(&t[i], NULL, fn, &data[i]);\n>      restore_sigchain_signals(&guard);\n> > plus a git_pthread_create() wrapper on top for the single-thread\n> call sites.  The loops I have in mind are preload_index(),\n> index-pack, pack-objects, grep, name-hash and the read-cache entry\n> loader; the fsmonitor--daemon and simple-ipc threads I would leave\n> alone for now, as they have their own lifecycle and signal\n> handling.\n> > On sigaction: agreed as well.  The handled signal is deferred by\n> default, so the remaining hole is a handler being interrupted by\n> one of the other common signals that share the same handler.  I\n> will set sa_mask to sigfillset() and save/restore the whole\n> struct sigaction, so pop() does not clobber the caller's\n> sa_flags/sa_mask.\n> > The one gap I cannot close is a thread created by library code\n> rather than by us.  libcurl's threaded resolver is the case I am\n> aware of, depending on how libcurl is built; I do not know of an\n> in-tree instance, and I will mention it in the cover letter rather\n> than claim it is covered.\n> > So I will drop this patch and build the series along those lines.\n> As you suggested, I will wait a few days for Peff and Junio to\n> comment before spending much time on it; if nobody objects I will\n> send the replacement as v2.\n> > Thanks,\n> ian4hu\n\n\n"},{"id":"556861","messageId":"auRZNlHezwALJOD5@ugly.lan","threadId":"66704","inReplyTo":"4c2728ca-5511-4c30-a2ef-6c32fe7a3e9e@gmail.com","subject":"Re: [PATCH] sigchain: recover from concurrent double-pops of the same signal","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2026-10-30T08:45:42Z","receivedAt":"2026-10-30T08:45:42Z","isPatch":true,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"On Thu, Oct 29, 2026 at 04:03:18PM +0000, Phillip Wood wrote:\n>On 29/10/2026 14:15, ian4hu wrote:\n>> I left SIGPIPE out precisely to keep the \"upstream of a pipe\n>> dies of SIGPIPE\" behaviour that common-init.c restores.  The set I\n>> plan to block is SIGINT, SIGHUP, SIGTERM and SIGQUIT.  If you\n>> think SIGPIPE belongs in it too, I will add it.\n>\n>I think we want to block all signals when we create a thread, so that >all signals are handled by the main (initial) thread.\n>\nthat wording again does not address the fact that sigpipe is different due to being thread-directed [1]. even if the outcome is identical, it needs to be reasoned about separately.\n\n[1] https://stackoverflow.com/questions/21718311/when-multi-thread-program-receive-a-sigpipe-signal-because-send-which-thread-wo\n\n\n"},{"id":"557024","messageId":"97b9f962-78c4-43cf-9782-4d479b57f103@gmail.com","threadId":"66704","inReplyTo":"auRZNlHezwALJOD5@ugly.lan","subject":"Re: [PATCH] sigchain: recover from concurrent double-pops of the same signal","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-31T14:50:36Z","receivedAt":"2026-10-31T14:50:36Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 30/10/2026 08:45, Oswald Buddenhagen wrote:\n> On Thu, Oct 29, 2026 at 04:03:18PM +0000, Phillip Wood wrote:\n>> On 29/10/2026 14:15, ian4hu wrote:\n>>> I left SIGPIPE out precisely to keep the \"upstream of a pipe\n>>> dies of SIGPIPE\" behaviour that common-init.c restores.  The set I\n>>> plan to block is SIGINT, SIGHUP, SIGTERM and SIGQUIT.  If you\n>>> think SIGPIPE belongs in it too, I will add it.\n>>\n>> I think we want to block all signals when we create a thread, so that >> all signals are handled by the main (initial) thread.\n>>\n> that wording again does not address the fact that sigpipe is different > due to being thread-directed [1]. even if the outcome is identical, it > needs to be reasoned about separately.\n\nOh, thanks for pointing that out, I hadn't realized some signals were directed at a specific thread rather than the process. According to my copy of The Linux Programming interface SIGBUS, SIGFPE, SIGILL and SIGSEGV are all thread-directed as well so, to ensure the process is killed if we receive one of those signals, we shouldn't be blocking any of those either. sigchain_push_common() installs a handler for SIGPIPE so, in principle, we could end up unwinding the chain in two threads, I'm not sure if that is likely in practice. If that is an issue, maybe we could set a flag in the signal handler to indicate it has already run (though I'm not sure it is possible to do that race-free without something like atomic_flag_test_and_set()).\n\nThanks\n\nPhillip\n\n> [1] https://stackoverflow.com/questions/21718311/when-multi-thread- > program-receive-a-sigpipe-signal-because-send-which-thread-wo\n\n\n"}]}