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

Re: [PATCH] t0008: avoid SIGPIPE race condition on fifo

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 12, 2013, 16:23 UTC
Message-ID
<7vbo67oig5.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130712103522.GA4750@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 15 quoted lines
> Subject: [PATCH] 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.
Ahh, figures.

I wish I were smart enough to figure that out immediately after seeing the test that does funny things to "in" with "9".

Thanks.
Show 41 quoted lines
> 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 <peff@peff.net>
> ---
>  t/t0008-ignores.sh | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
> index a56db80..c29342d 100755
> --- a/t/t0008-ignores.sh
> +++ b/t/t0008-ignores.sh
> @@ -697,13 +697,21 @@ test_expect_success PIPE 'streaming support for --stdin' '
>  	# shell, and then echo to the fd. We make sure to close it at
>  	# the end, so that the subprocess does get EOF and dies
>  	# properly.
> +	#
> +	# Similarly, we must keep "out" open so that check-ignore does
> +	# not ever get SIGPIPE trying to write to us. Not only would that
> +	# produce incorrect results, but then there would be no writer on the
> +	# other end of the pipe, and we would potentially block forever trying
> +	# to open it.
>  	exec 9>in &&
> +	exec 8<out &&
>  	test_when_finished "exec 9>&-" &&
> +	test_when_finished "exec 8<&-" &&
>  	echo >&9 one &&
> -	read response <out &&
> +	read response <&8 &&
>  	echo "$response" | grep "^\.gitignore:1:one	one" &&
>  	echo >&9 two &&
> -	read response <out &&
> +	read response <&8 &&
>  	echo "$response" | grep "^::	two"
>  '
Previous: Jeff KingNext: Jeff King
Message 7 of 10 in “t0008 hang on streaming test (OS X)”
  1. Brian GernhardtJul 10, 2013
  2. Antoine PelisseJul 10, 2013
  3. Brian GernhardtJul 11, 2013
  4. Jeff KingJul 11, 2013
  5. Junio C HamanoJul 11, 2013
  6. t0008: avoid SIGPIPE race condition on fifoJeff King, Jul 12, 2013
  7. Junio C HamanoJul 12, 2013
  8. Jeff KingJul 12, 2013
  9. Brian GernhardtJul 12, 2013
  10. Brian GernhardtJul 11, 2013

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.