Skip to content

Commit 246f269

Browse files
derrickstoleedscho
authored andcommitted
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 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 <[email protected]>
1 parent 6f12598 commit 246f269

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

upload-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,12 @@ static void check_non_tip(struct upload_pack_data *data)
765765
for (i = 0; i < data->want_obj.nr; i++) {
766766
struct object *o = data->want_obj.objects[i].item;
767767
if (!is_our_ref(o, data->allow_uor)) {
768+
warning("git upload-pack: not our ref %s",
769+
oid_to_hex(&o->oid));
768770
packet_writer_error(&data->writer,
769771
"upload-pack: not our ref %s",
770772
oid_to_hex(&o->oid));
771-
die("git upload-pack: not our ref %s",
772-
oid_to_hex(&o->oid));
773+
exit(1);
773774
}
774775
}
775776
}

0 commit comments

Comments
 (0)