receive-pack: ignore SIGPIPE while reporting status to client

Before running the post-receive hook, status info is reported back to the client. If a remote client exits before or during the status report, receive-pack is killed by SIGPIPE and post-receive is never executed. The post-receive hook is often used to send email notifications (see contrib/hooks/post-receive-email), update bug trackers, start automatic builds, etc. Not executing it after an interrupted yet "successful" push can lead to inconsistencies. Ignore SIGPIPE before reporting status to the client to increase the chances of post-receive running if pre-receive was successful. This does not guarantee 100% consistency but it should resist early disconnection by the client. Signed-off-by: Robin Jarry <robin@jarry.cc> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Robin Jarry committed Nov 10, 2021 at 10:29 UTC d34182b9e37fc72e04e40e834775a1c29e80c970
1 file changed +2
builtin/receive-pack.c
+2
@@ -2563,10 +2563,12 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
2563 &push_options);
2564 if (pack_lockfile)
2565 unlink_or_warn(pack_lockfile);
2566 + sigchain_push(SIGPIPE, SIG_IGN);
2567 if (report_status_v2)
2568 report_v2(commands, unpack_status);
2569 else if (report_status)
2570 report(commands, unpack_status);
2571 + sigchain_pop(SIGPIPE);
2572 run_receive_hook(commands, "post-receive", 1,
2573 &push_options);
2574 run_update_post_hook(commands);