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

[PATCH 1/6] receive-pack: fix deadlock when we cannot create tmpdir

From
Jeff King <peff@peff.net>
Date
Mar 7, 2017, 13:35 UTC
Message-ID
<20170307133534.bgar57ojq52snns3@sigill.intra.peff.net>
In-Reply-To
<20170307133437.qee2jtynbiwf6uzr@sigill.intra.peff.net>

The err_fd descriptor passed to the unpack() function is intended to be handed off to the child index-pack, and our async muxer will read until it gets EOF. However, if we encounter an error before handing off the descriptor, we must manually close(err_fd). Otherwise we will be waiting for our muxer to finish, while the muxer is waiting for EOF on err_fd.

We fixed an identical deadlock already in 49ecfa13f (receive-pack: close sideband fd on early pack errors, 2013-04-19). But since then, the function grew a new early-return in 722ff7f87 (receive-pack: quarantine objects until pre-receive accepts, 2016-10-03), when we fail to create a temporary directory. This return needs the same treatment.

Reported-by: Horst Schirmeier <horst@schirmeier.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/receive-pack.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 9ed8fbbfa..f2c6953a3 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1667,8 +1667,11 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 	}
 
 	tmp_objdir = tmp_objdir_create();
-	if (!tmp_objdir)
+	if (!tmp_objdir) {
+		if (err_fd > 0)
+			close(err_fd);
 		return "unable to create temporary object directory";
+	}
 	child.env = tmp_objdir_env(tmp_objdir);
 
 	/*
-- 
2.12.0.429.gde83c8049
Previous: Jeff KingNext: Jeff King
Message 2 of 12 in “deadlock regression in v2.11.0 with failed mkdtemp”
  1. 0/6 deadlock regression in v2.11.0 with failed mkdtempJeff King, Mar 7, 2017
  2. 1/6 receive-pack: fix deadlock when we cannot create tmpdirJeff King, Mar 7, 2017
  3. 2/6 send-pack: extract parsing of "unpack" responseJeff King, Mar 7, 2017
  4. 6/6 send-pack: report signal death of pack-objectsJeff King, Mar 7, 2017
  5. 5/6 send-pack: read "unpack" status even on pack-objects failureJeff King, Mar 7, 2017
  6. 4/6 send-pack: improve unpack-status error messagesJeff King, Mar 7, 2017
  7. Junio C HamanoMar 7, 2017
  8. Jeff KingMar 8, 2017
  9. Junio C HamanoMar 8, 2017
  10. Jeff KingMar 7, 2017
  11. 3/6 send-pack: use skip_prefix for parsing unpack statusJeff King, Mar 7, 2017
  12. Horst SchirmeierMar 8, 2017

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.