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

[PATCH v4] receive-pack: check if client is alive before completing the push

From
RJRobin Jarry <robin.jarry@6wind.com>
Date
Jan 28, 2022, 19:48 UTC
Message-ID
<20220128194811.3396281-1-robin.jarry@6wind.com>
In-Reply-To
<20220127215553.1386024-1-robin.jarry@6wind.com>

Abort the push operation (i.e. do not migrate the objects from temporary to permanent storage) if the client has disconnected while the pre-receive hook was running.

This reduces the risk of inconsistencies on network errors or if the user hits ctrl-c while the pre-receive hook is running.

Send a keepalive packet (empty) on sideband 2 (the one to report progress). If the client has exited the write() operation should fail and the push will be aborted. This only works when sideband* capabilities are advertised by the client.

Note: if the write() operation fails, receive-pack will likely be killed
via SIGPIPE and even so, since the client is likely gone already, the
error strings will go nowhere. I only added them for code consistency.
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
---
v3 -> v4:
  - reworded the comment block s/ensure/notice/
  - used write_in_full() instead of write_or_die()
  - set error_string fields for code consistency
 builtin/receive-pack.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 9f4a0b816cf9..f8b9a9312733 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1971,6 +1971,22 @@ static void execute_commands(struct command *commands,
 		return;
 	}
 
+	/*
+	 * Send a keepalive packet on sideband 2 (progress info) to notice
+	 * a client that has disconnected (e.g. killed with ^C) while
+	 * pre-receive was running.
+	 */
+	if (use_sideband) {
+		static const char buf[] = "0005\2";
+		if (write_in_full(1, buf, sizeof(buf) - 1) < 0) {
+			for (cmd = commands; cmd; cmd = cmd->next) {
+				if (!cmd->error_string)
+					cmd->error_string = "pusher went away";
+			}
+			return;
+		}
+	}
+
 	/*
 	 * Now we'll start writing out refs, which means the objects need
 	 * to be in their final positions so that other processes can see them.
-- 
2.35.0.4.g44a5d4affccf
Previous: Robin JarryNext: Ævar Arnfjörð Bjarmason
Message 16 of 20 in “receive-pack: interrupt pre-receive when client disconnects”
  1. receive-pack: interrupt pre-receive when client disconnectsRobin Jarry, Jan 25, 2022
  2. Jiang XinJan 26, 2022
  3. Robin JarryJan 26, 2022
  4. receive-pack: add option to interrupt pre-receive when client exitsRobin Jarry, Jan 26, 2022
  5. Jiang XinJan 27, 2022
  6. Robin JarryJan 27, 2022
  7. Junio C HamanoJan 27, 2022
  8. Robin JarryJan 27, 2022
  9. Junio C HamanoJan 27, 2022
  10. Robin JarryJan 27, 2022
  11. receive-pack: check if client is alive before completing the pushRobin Jarry, Jan 27, 2022
  12. Junio C HamanoJan 28, 2022
  13. Robin JarryJan 28, 2022
  14. Junio C HamanoJan 28, 2022
  15. Robin JarryJan 28, 2022
  16. receive-pack: check if client is alive before completing the pushRobin Jarry, Jan 28, 2022
  17. Ævar Arnfjörð BjarmasonFeb 4, 2022
  18. Junio C HamanoFeb 4, 2022
  19. Robin JarryFeb 7, 2022
  20. Junio C HamanoJan 27, 2022

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.