From: Robin Jarry <robin.jarry@6wind.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Emily Shaffer <emilyshaffer@google.com>,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
Patryk Obara <patryk.obara@gmail.com>,
Jiang Xin <zhiyou.jx@alibaba-inc.com>,
Robin Jarry <robin.jarry@6wind.com>
Subject: [PATCH v4] receive-pack: check if client is alive before completing the push
Date: Fri, 28 Jan 2022 20:48:11 +0100 [thread overview]
Message-ID: <20220128194811.3396281-1-robin.jarry@6wind.com> (raw)
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
next prev parent reply other threads:[~2022-01-28 19:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 9:54 [PATCH] receive-pack: interrupt pre-receive when client disconnects Robin Jarry
2022-01-26 7:17 ` Jiang Xin
2022-01-26 12:46 ` Robin Jarry
2022-01-26 21:44 ` [PATCH v2] receive-pack: add option to interrupt pre-receive when client exits Robin Jarry
2022-01-27 3:21 ` Jiang Xin
2022-01-27 8:38 ` Robin Jarry
2022-01-27 4:36 ` Junio C Hamano
2022-01-27 9:32 ` Robin Jarry
2022-01-27 18:26 ` Junio C Hamano
2022-01-27 20:53 ` Robin Jarry
2022-01-27 21:55 ` [PATCH v3] receive-pack: check if client is alive before completing the push Robin Jarry
2022-01-28 1:19 ` Junio C Hamano
2022-01-28 9:13 ` Robin Jarry
2022-01-28 17:52 ` Junio C Hamano
2022-01-28 19:32 ` Robin Jarry
2022-01-28 19:48 ` Robin Jarry [this message]
2022-02-04 11:37 ` [PATCH v4] " Ævar Arnfjörð Bjarmason
2022-02-04 19:19 ` Junio C Hamano
2022-02-07 19:26 ` Robin Jarry
2022-01-27 23:47 ` [PATCH v2] receive-pack: add option to interrupt pre-receive when client exits Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220128194811.3396281-1-robin.jarry@6wind.com \
--to=robin.jarry@6wind.com \
--cc=emilyshaffer@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=nicolas.dichtel@6wind.com \
--cc=patryk.obara@gmail.com \
--cc=zhiyou.jx@alibaba-inc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).