From aa226bbb6ba913db0ce428641d4fde733b63f0a8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Dec 2011 15:17:01 -0400 Subject: [PATCH] Consume all stdin when rcs_receive short-circuits, to avoid git SIPIPE race. 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 What turned out to be going on was 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 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 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. I have written to the git mailing list about this. As a workaround, consume all stdin before exiting. --- IkiWiki/Receive.pm | 9 ++++++++- debian/changelog | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm index c73adfbbb..5908e09f9 100644 --- a/IkiWiki/Receive.pm +++ b/IkiWiki/Receive.pm @@ -35,10 +35,17 @@ EOF } "u != $uid"; } @{$config{untrusted_committers}}). - ") exit(0);\n"; + ") {\n"; $ret.=<<"EOF"; + /* Trusted user. + * Consume all stdin before exiting, as git may + * otherwise be unhappy. */ + char buf[256]; + while (read(0, &buf, 256) != 0) {} + exit(0); + } asprintf(&s, "CALLER_UID=%i", u); newenviron[i++]=s; } diff --git a/debian/changelog b/debian/changelog index 0c64875f1..ccdeb8300 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +ikiwiki (3.20111108) UNRELEASED; urgency=low + + * Consume all stdin when rcs_receive short-circuits, to avoid git SIPIPE race. + + -- Joey Hess Mon, 05 Dec 2011 15:14:48 -0400 + ikiwiki (3.20111107) unstable; urgency=low * img: Bugfix to width/height tags for scaled down image when only -- 2.26.2