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

[PATCH v3] receive-pack: ignore SIGPIPE while reporting status to client

From
Robin Jarry <robin@jarry.cc>
Date
Nov 10, 2021, 09:29 UTC
Message-ID
<20211110092942.1648429-1-robin@jarry.cc>
In-Reply-To
<20211106220358.144886-1-robin@jarry.cc>

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>
---
Changes since v2:
* Updated commit log with more pertinent info.
* Only ignore SIGPIPE while reporting status, *after* removing the lock
  file.
 builtin/receive-pack.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 49b846d96052..2f4a38adfe2c 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2566,10 +2566,12 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 				 &push_options);
 		if (pack_lockfile)
 			unlink_or_warn(pack_lockfile);
+		sigchain_push(SIGPIPE, SIG_IGN);
 		if (report_status_v2)
 			report_v2(commands, unpack_status);
 		else if (report_status)
 			report(commands, unpack_status);
+		sigchain_pop(SIGPIPE);
 		run_receive_hook(commands, "post-receive", 1,
 				 &push_options);
 		run_update_post_hook(commands);
-- 
2.34.0.rc2.2.gbcf7eca935e4
Previous: Robin JarryNext: Robin Jarry
Message 10 of 11 in “receive-pack: run post-receive before reporting status”
  1. receive-pack: run post-receive before reporting statusRobin Jarry, Nov 4, 2021
  2. Ævar Arnfjörð BjarmasonNov 6, 2021
  3. Robin JarryNov 6, 2021
  4. receive-pack: ignore SIGPIPE while reporting status to clientRobin Jarry, Nov 6, 2021
  5. Junio C HamanoNov 9, 2021
  6. Robin JarryNov 9, 2021
  7. Junio C HamanoNov 9, 2021
  8. receive-pack: interrupt pre-receive when client disconnectsRobin Jarry, Nov 10, 2021
  9. Robin JarryDec 29, 2021
  10. receive-pack: ignore SIGPIPE while reporting status to clientRobin Jarry, Nov 10, 2021
  11. Robin JarryNov 18, 2021

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.