From: Andrew Au <cshung@gmail.com>
To: git@vger.kernel.org
Cc: peff@peff.net, gitster@pobox.com, Andrew Au <cshung@gmail.com>,
Copilot <223556219+Copilot@users.noreply.github.com>
Subject: [PATCH v3] transport-helper, connect: use clean_on_exit to reap children on abnormal exit
Date: Thu, 12 Mar 2026 19:55:59 +0000 [thread overview]
Message-ID: <20260312195813.4006430-1-cshung@gmail.com> (raw)
In-Reply-To: <20260311184206.GA1911377@coredump.intra.peff.net>
When a long-running service (e.g., a source indexer) runs as PID 1
inside a container and repeatedly spawns git, git may in turn spawn
child processes such as git-remote-https or ssh. If git exits abnormally
(e.g., via exit(128) on a transport error), the normal cleanup paths
(disconnect_helper, finish_connect) are bypassed, and these children are
never waited on. The children are reparented to PID 1, which does not
reap them, so they accumulate as zombies over time.
Set clean_on_exit and wait_after_clean on child_process structs in both
transport-helper.c and connect.c so that the existing run-command
cleanup infrastructure handles reaping on any exit path. This avoids
rolling custom atexit handlers that call finish_command(), which could
deadlock if the child is blocked waiting for the parent to close a pipe.
The clean_on_exit mechanism sends SIGTERM first, then waits, ensuring
the child terminates promptly. It also handles signal-based exits, not
just atexit.
Signed-off-by: Andrew Au <cshung@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
Thanks to Jeff King for suggesting the clean_on_exit approach,
which is simpler and avoids potential deadlocks from the atexit
handler in v2. Also thanks to Junio for catching the inaccurate
description of the PID 1 scenario.
connect.c | 4 ++++
transport-helper.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/connect.c b/connect.c
index eef752f14..5039adca7 100644
--- a/connect.c
+++ b/connect.c
@@ -989,6 +989,8 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
strvec_push(&proxy->args, port);
proxy->in = -1;
proxy->out = -1;
+ proxy->clean_on_exit = 1;
+ proxy->wait_after_clean = 1;
if (start_command(proxy))
die(_("cannot start proxy %s"), git_proxy_command);
fd[0] = proxy->out; /* read from proxy stdout */
@@ -1447,6 +1449,8 @@ struct child_process *git_connect(int fd[2], const char *url,
}
strvec_push(&conn->args, cmd.buf);
+ conn->clean_on_exit = 1;
+ conn->wait_after_clean = 1;
if (start_command(conn))
die(_("unable to fork"));
diff --git a/transport-helper.c b/transport-helper.c
index e95267a4a..6633a999b 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -140,6 +140,8 @@ static struct child_process *get_helper(struct transport *transport)
helper->trace2_child_class = helper->args.v[0]; /* "remote-<name>" */
+ helper->clean_on_exit = 1;
+ helper->wait_after_clean = 1;
code = start_command(helper);
if (code < 0 && errno == ENOENT)
die(_("unable to find remote helper for '%s'"), data->name);
--
2.43.0
next prev parent reply other threads:[~2026-03-12 19:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 16:51 [PATCH 0/1] Fix zombie children when git is PID 1 in containers Andrew Au
2026-02-23 16:51 ` [PATCH 1/1] transport-helper, connect: add atexit handler to reap children on abnormal exit Andrew Au
2026-02-23 17:14 ` Kristoffer Haugsbakk
2026-02-23 18:12 ` Andrew Au
2026-03-11 14:20 ` [PATCH v2] " Andrew Au
2026-03-11 17:58 ` Junio C Hamano
2026-03-11 18:19 ` Andrew Au
2026-03-11 19:38 ` Junio C Hamano
2026-03-11 18:42 ` Jeff King
2026-03-12 19:55 ` Andrew Au [this message]
2026-03-12 20:40 ` [PATCH v3] transport-helper, connect: use clean_on_exit " Jeff King
2026-03-12 20:41 ` Jeff King
2026-03-12 20:49 ` Junio C Hamano
2026-03-12 21:49 ` [PATCH v4] " Andrew Au
2026-03-12 22:04 ` Junio C Hamano
2026-03-14 16:08 ` Jeff King
2026-03-14 17:24 ` Junio C Hamano
2026-03-16 20:31 ` Junio C Hamano
2026-03-16 21:19 ` Jeff King
2026-03-16 21:24 ` Junio C Hamano
2026-03-11 21:15 ` [PATCH 0/1] Fix zombie children when git is PID 1 in containers brian m. carlson
2026-03-12 19:40 ` Andrew Au
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260312195813.4006430-1-cshung@gmail.com \
--to=cshung@gmail.com \
--cc=223556219+Copilot@users.noreply.github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox