]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t1400: avoid SIGPIPE race condition on fifo
authorJeff King <peff@peff.net>
Wed, 15 Sep 2021 17:24:52 +0000 (13:24 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Sep 2021 20:06:50 +0000 (13:06 -0700)
t1400.190 sometimes fails or even hangs because of the way it uses
fifos. Our goal is to interactively read and write lines from
update-ref, so we have two fifos, in and out. We open a descriptor
connected to "in" and redirect output to that, so that update-ref does
not see EOF as it would if we opened and closed it for each "echo" call.

But we don't do the same for the output. This leads to a race where our
"read response <out" has not yet opened the fifo, but update-ref tries
to write to it and gets SIGPIPE. This can result in the test failing, or
worse, hanging as we wait forever for somebody to write to the pipe.

This is the same proble we fixed in 4783e7ea83 (t0008: avoid SIGPIPE
race condition on fifo, 2013-07-12), and we can fix it the same way, by
opening a second long-running descriptor.

Before this patch, running:

  ./t1400-update-ref.sh --run=1,190 --stress

failed or hung within a few dozen iterations. After it, I ran it for
several hundred without problems.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1400-update-ref.sh

index 1e754e258fecc538bd6e34439f1939d88a6a66e5..0d4f73acaa87e5f29a6346abb8d1dc6736d41794 100755 (executable)
@@ -1603,11 +1603,13 @@ test_expect_success PIPE 'transaction flushes status updates' '
        (git update-ref --stdin <in >out &) &&
 
        exec 9>in &&
+       exec 8<out &&
        test_when_finished "exec 9>&-" &&
+       test_when_finished "exec 8<&-" &&
 
        echo "start" >&9 &&
        echo "start: ok" >expected &&
-       read line <out &&
+       read line <&8 &&
        echo "$line" >actual &&
        test_cmp expected actual &&
 
@@ -1615,7 +1617,7 @@ test_expect_success PIPE 'transaction flushes status updates' '
 
        echo prepare >&9 &&
        echo "prepare: ok" >expected &&
-       read line <out &&
+       read line <&8 &&
        echo "$line" >actual &&
        test_cmp expected actual &&
 
@@ -1625,7 +1627,7 @@ test_expect_success PIPE 'transaction flushes status updates' '
 
        echo commit >&9 &&
        echo "commit: ok" >expected &&
-       read line <out &&
+       read line <&8 &&
        echo "$line" >actual &&
        test_cmp expected actual
 '