Skip to content

Commit 1fd0e32

Browse files
committed
upload-pack: fix race condition in error messages
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 remove this failure, follow this process instead: 1. Write an error message to stderr. 2. Write an error message across the connection. 3. Flush the connection. 4. 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. The flush is important for avoiding a client error when the connection is cut in the middle of a packet line. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 5fa0f52 commit 1fd0e32

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

upload-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,13 @@ static void check_non_tip(struct object_array *want_obj,
613613
for (i = 0; i < want_obj->nr; i++) {
614614
struct object *o = want_obj->objects[i].item;
615615
if (!is_our_ref(o)) {
616+
error("git upload-pack: not our ref %s",
617+
oid_to_hex(&o->oid));
616618
packet_writer_error(writer,
617619
"upload-pack: not our ref %s",
618620
oid_to_hex(&o->oid));
619-
die("git upload-pack: not our ref %s",
620-
oid_to_hex(&o->oid));
621+
packet_writer_flush(writer);
622+
exit(1);
621623
}
622624
}
623625
}

0 commit comments

Comments
 (0)