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

hooks that do not consume stdin sometimes crash git with SIGPIPE

From
Joey Hess <joey@kitenet.net>
Date
Dec 5, 2011, 19:29 UTC
Message-ID
<20111205192930.GA32463@gnu.kitenet.net>
In-Reply-To
<20110829203107.GA4946@gnu.kitenet.net>

We had a weird problem where, after moving to a new, faster server, "git push" would sometimes fail like this:

Unpacking objects: 100% (3/3), done. fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly

Turns out that git-receive-pack was dying due to an uncaught SIGPIPE. The SIGPIPE occurred when it tried to write to the pre-receive hook's stdin. The pre-receive hook, in this case, was able to do all the checks it needed to do[1] without the input, and so did exit(0) without consuming it.

Apparently that causes a race. Most of the time, git forks the hook, writes output to the hook, and then the hook runs, ignores it, and exits. But sometimes, on our new faster (and SMP) server, git forked the hook, and it ran, and exited, before git got around to writing to it, resulting in the SIGPIPE.

write(7, "c9f98c67d70a1cfeba382ec27d87644a"..., 100) = -1 EPIPE (Broken pipe) --- SIGPIPE (Broken pipe) @ 0 (0) ---

I think git should ignore SIGPIPE when writing to hooks. Otherwise, hooks may have to go out of their way to consume all input, and as I've seen, the races when they fail to do this can lurk undiscovered.

Note that I encountered this same sort of problem from another direction (involving smudge filters) not long ago, and sent a patch, in <20110829203107.GA4946@gnu.kitenet.net>. That wasn't applied, and is in different code than the case I outlined above.

-- 
see shy jo

[1] If you're wondering, it only needed to check that the push was
    coming from a trusted UID. With an untrusted UID, it did further
    checks that consumed the stdin.
Previous: Joey HessNext: Jeff King
Message 4 of 7 in “do not require filters to consume stdin”
  1. do not require filters to consume stdinJoey Hess, Aug 29, 2011
  2. Junio C HamanoAug 29, 2011
  3. Joey HessAug 30, 2011
  4. hooks that do not consume stdin sometimes crash git with SIGPIPEJoey Hess, Dec 5, 2011
  5. Jeff KingDec 5, 2011
  6. Junio C HamanoDec 6, 2011
  7. Joey HessDec 6, 2011

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.