git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:09 UTC

Re: [PATCH v4] transport-helper, connect: use clean_on_exit to reap children on abnormal exit

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 12, 2026, 22:04 UTC
Message-ID
<xmqqsea4aen2.fsf@gitster.g>
In-Reply-To
<20260312214945.4050010-1-cshung@gmail.com>
Andrew Au <cshung@gmail.com> writes:
Show 23 quoted lines
> 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>
> ---
>  connect.c          | 4 ++++
>  transport-helper.c | 2 ++
>  2 files changed, 6 insertions(+)
Thanks, queued.
Show 36 quoted lines
>
> 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);
Previous: Andrew AuNext: Jeff King
Message 17 of 22 in “Fix zombie children when git is PID 1 in containers”
  1. 0/1 Fix zombie children when git is PID 1 in containersAndrew Au, Feb 23, 2026
  2. 1/1 transport-helper, connect: add atexit handler to reap children on abnormal exitAndrew Au, Feb 23, 2026
  3. Kristoffer HaugsbakkFeb 23, 2026
  4. Andrew AuFeb 23, 2026
  5. transport-helper, connect: add atexit handler to reap children on abnormal exitAndrew Au, Mar 11, 2026
  6. Junio C HamanoMar 11, 2026
  7. Andrew AuMar 11, 2026
  8. Jeff KingMar 11, 2026
  9. Junio C HamanoMar 11, 2026
  10. brian m. carlsonMar 11, 2026
  11. Andrew AuMar 12, 2026
  12. transport-helper, connect: use clean_on_exit to reap children on abnormal exitAndrew Au, Mar 12, 2026
  13. Jeff KingMar 12, 2026
  14. Jeff KingMar 12, 2026
  15. Junio C HamanoMar 12, 2026
  16. transport-helper, connect: use clean_on_exit to reap children on abnormal exitAndrew Au, Mar 12, 2026
  17. Junio C HamanoMar 12, 2026
  18. Jeff KingMar 14, 2026
  19. Junio C HamanoMar 14, 2026
  20. Junio C HamanoMar 16, 2026
  21. Jeff KingMar 16, 2026
  22. Junio C HamanoMar 16, 2026

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.