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

[PATCH 1/1] upload-pack: fix race condition in error messages

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 28, 2019, 01:43 UTC
Message-ID
<5c313aba7e97cb93e7d07f6d5dfaf0febe8a2f8b.1566956608.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.324.git.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

Test t5516-fetch-push.sh has a test 'deny fetch unreachable SHA1, allowtipsha1inwant=true' that checks stderr for a specific error string from the remote. In some build environments the error sent over the remote connection gets mingled with the error from the die() statement. Since both signals are being output to the same file descriptor (but from parent and child processes), the output we are matching with grep gets split.

To reduce the risk of this failure, follow this process instead:
1. Write an error message to stderr.
2. Write an error message across the connection.
3. exit(1).

This reorders the events so the error is written entirely before the client receives a message from the remote, removing the race condition.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 upload-pack.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/upload-pack.c b/upload-pack.c
index 222cd3ad89..b0d3e028d1 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -613,11 +613,12 @@ static void check_non_tip(struct object_array *want_obj,
 	for (i = 0; i < want_obj->nr; i++) {
 		struct object *o = want_obj->objects[i].item;
 		if (!is_our_ref(o)) {
+			warning("git upload-pack: not our ref %s",
+				oid_to_hex(&o->oid));
 			packet_writer_error(writer,
 					    "upload-pack: not our ref %s",
 					    oid_to_hex(&o->oid));
-			die("git upload-pack: not our ref %s",
-			    oid_to_hex(&o->oid));
+			exit(1);
 		}
 	}
 }
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: SZEDER Gábor
Message 2 of 15 in “upload-pack: fix race condition in t5516”
  1. 0/1 upload-pack: fix race condition in t5516Derrick Stolee via GitGitGadget, Aug 28, 2019
  2. 1/1 upload-pack: fix race condition in error messagesDerrick Stolee via GitGitGadget, Aug 28, 2019
  3. SZEDER GáborAug 28, 2019
  4. Jeff KingAug 28, 2019
  5. Jeff KingAug 28, 2019
  6. SZEDER GáborAug 28, 2019
  7. Derrick StoleeAug 29, 2019
  8. Jeff KingAug 29, 2019
  9. Derrick StoleeAug 29, 2019
  10. Jeff KingAug 29, 2019
  11. SZEDER GáborAug 29, 2019
  12. SZEDER GáborAug 29, 2019
  13. SZEDER GáborAug 30, 2019
  14. Jeff KingSep 4, 2019
  15. SZEDER GáborSep 10, 2019

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.