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

Re: [PATCH v2 4/4] diff --no-index: support reading from named pipes

From
Jeff King <peff@peff.net>
Date
Aug 9, 2023, 17:17 UTC
Message-ID
<20230809171731.GA3663609@coredump.intra.peff.net>
In-Reply-To
<4e05a0be54f66f2b394642762832e426a545426c.1688586536.git.phillip.wood@dunelm.org.uk>
On Wed, Jul 05, 2023 at 08:49:30PM +0100, Phillip Wood wrote:
Show 39 quoted lines
> +test_expect_success PIPE 'diff --no-index refuses to diff a named pipe and a directory' '
> +	test_when_finished "rm -f pipe" &&
> +	mkfifo pipe &&
> +	{
> +		(>pipe) &
> +	} &&
> +	test_when_finished "kill $!" &&
> +	test_must_fail git diff --no-index -- pipe a 2>err &&
> +	grep "fatal: cannot compare a named pipe to a directory" err
> +'
> +
> +test_expect_success PIPE,SYMLINKS 'diff --no-index reads from pipes' '
> +	test_when_finished "rm -f old new new-link" &&
> +	mkfifo old &&
> +	mkfifo new &&
> +	ln -s new new-link &&
> +	{
> +		(test_write_lines a b c >old) &
> +	} &&
> +	test_when_finished "! kill $!" &&
> +	{
> +		(test_write_lines a x c >new) &
> +	} &&
> +	test_when_finished "! kill $!" &&
> +
> +	cat >expect <<-EOF &&
> +	diff --git a/old b/new-link
> +	--- a/old
> +	+++ b/new-link
> +	@@ -1,3 +1,3 @@
> +	 a
> +	-b
> +	+x
> +	 c
> +	EOF
> +
> +	test_expect_code 1 git diff --no-index old new-link >actual &&
> +	test_cmp expect actual
> +'

I've had t4053 hang for me once or twice in the last few days. I haven't managed to pinpoint the problem, but I did notice that running it with --stress seems to occasionally fail in thie "reads from pipes" test.

The problem is that the "kill" is racy. Even after we've read all of the input from those sub-processes, they might still be hanging around waiting to exit when our test_when_finished runs. And then kill will return "0". So I think we need to either:

  1. Soften the when_finished to "kill $! || true" so that we are OK if
     they are still there.
  2. If the diff command completed as expected, it should be safe to
     "wait" for each of them to confirm that they successfully wrote
     everything. I'm not sure it buys us much over testing the output
     from "diff", though.

I still don't see where the hang comes from, though. It might be unrelated. I'll try to examine more next time I catch it in the act.

-Peff
Previous: Junio C HamanoNext: Phillip Wood
Message 14 of 17 in “diff --no-index: support reading from named pipes”
  1. 0/3 diff --no-index: support reading from named pipesPhillip Wood, Jun 27, 2023
  2. 1/3 diff --no-index: die on error reading stdinPhillip Wood, Jun 27, 2023
  3. 2/3 t4054: test diff --no-index with stdinPhillip Wood, Jun 27, 2023
  4. 3/3 diff --no-index: support reading from named pipesPhillip Wood, Jun 27, 2023
  5. Junio C HamanoJun 27, 2023
  6. Phillip WoodJun 28, 2023
  7. 0/4 diff --no-index: support reading from named pipesPhillip Wood, Jul 5, 2023
  8. 1/4 diff --no-index: refuse to compare stdin to a directoryPhillip Wood, Jul 5, 2023
  9. Junio C HamanoJul 5, 2023
  10. 3/4 t4054: test diff --no-index with stdinPhillip Wood, Jul 5, 2023
  11. Junio C HamanoJul 5, 2023
  12. 4/4 diff --no-index: support reading from named pipesPhillip Wood, Jul 5, 2023
  13. Junio C HamanoJul 5, 2023
  14. Jeff KingAug 9, 2023
  15. Phillip WoodAug 10, 2023
  16. 2/4 diff --no-index: die on error reading stdinPhillip Wood, Jul 5, 2023
  17. Junio C HamanoJul 5, 2023

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.