Skip to content

Commit 4783e7e

Browse files
peffgitster
authored andcommitted
t0008: avoid SIGPIPE race condition on fifo
To test check-ignore's --stdin feature, we use two fifos to send and receive data. We carefully keep a descriptor to its input open so that it does not receive EOF between input lines. However, we do not do the same for its output. That means there is a potential race condition in which check-ignore has opened the output pipe once (when we read the first line), and then writes the second line before we have re-opened the pipe. In that case, check-ignore gets a SIGPIPE and dies. The outer shell then tries to open the output fifo but blocks indefinitely, because there is no writer. We can fix it by keeping a descriptor open through the whole procedure. This should also help if check-ignore dies for any other reason (we would already have opened the fifo and would therefore not block, but just get EOF on read). However, we are technically still susceptible to check-ignore dying early, before we have opened the fifo. This is an unlikely race and shouldn't generally happen in practice, though, so we can hopefully ignore it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b96114e commit 4783e7e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

t/t0008-ignores.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,13 +697,21 @@ test_expect_success PIPE 'streaming support for --stdin' '
697697
# shell, and then echo to the fd. We make sure to close it at
698698
# the end, so that the subprocess does get EOF and dies
699699
# properly.
700+
#
701+
# Similarly, we must keep "out" open so that check-ignore does
702+
# not ever get SIGPIPE trying to write to us. Not only would that
703+
# produce incorrect results, but then there would be no writer on the
704+
# other end of the pipe, and we would potentially block forever trying
705+
# to open it.
700706
exec 9>in &&
707+
exec 8<out &&
701708
test_when_finished "exec 9>&-" &&
709+
test_when_finished "exec 8<&-" &&
702710
echo >&9 one &&
703-
read response <out &&
711+
read response <&8 &&
704712
echo "$response" | grep "^\.gitignore:1:one one" &&
705713
echo >&9 two &&
706-
read response <out &&
714+
read response <&8 &&
707715
echo "$response" | grep "^:: two"
708716
'
709717

0 commit comments

Comments
 (0)