From: Joey Hess Date: Mon, 5 Dec 2011 19:17:01 +0000 (-0400) Subject: Consume all stdin when rcs_receive short-circuits, to avoid git SIPIPE race. X-Git-Tag: 3.20111229~73 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/aa226bbb6ba913db0ce428641d4fde733b63f0a8?hp=0dcb6f6539ad62d78214265e585b2516a3afe588 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. --- 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