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

Re: [PATCH v2] transport-helper, connect: add atexit handler to reap children on abnormal exit

From
Jeff King <peff@peff.net>
Date
Mar 11, 2026, 18:42 UTC
Message-ID
<20260311184206.GA1911377@coredump.intra.peff.net>
In-Reply-To
<20260311142021.3464789-1-cshung@gmail.com>
On Wed, Mar 11, 2026 at 02:20:21PM +0000, Andrew Au wrote:
Show 11 quoted lines
> +/*
> + * Ensure the connection child (ssh, proxy, or local git) is reaped on
> + * any exit path, mirroring the transport-helper.c atexit pattern.
> + */
> +static struct child_process *conn_to_reap;
> +
> +static void cleanup_conn_on_exit(void)
> +{
> +	if (conn_to_reap)
> +		finish_command(conn_to_reap);
> +}

This waits for the command to exit. Are we sure it will always do so, and it won't sometimes be waiting on us to do something (like close a pipe that is feeding it)? If not, then we can get deadlocks.

I think you actually want to kill(), then wait. There is already support for this in run-command.[ch]. You just need to set the clean_on_exit flag of the child_process struct.

I actually wonder if clean_on_exit should become the default behavior. It should be rare for our subprocesses to outlive us. Commit afe19ff7b5 (run-command: optionally kill children on exit, 2012-01-07) mentions the pager, but I don't think that was true even back then (we wait around for the pager to finish). There are a few cases where we spawn daemon programs, which would need to be marked as survivable. I think mostly we have not looked into it because somebody would have to look at each run_command() callsite.

Anyway, that is a bit of a tangent. I think it would be safe to mark the spots in this patch as clean_on_exit.

-Peff
Previous: Andrew AuNext: Junio C Hamano
Message 8 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.