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

cat-file timing window on Cygwin

From
Adam Dinwoodie <adam@dinwoodie.org>
Date
Aug 25, 2017, 11:25 UTC
Message-ID
<20170825112529.GA10378@dinwoodie.org>

As of v2.10.0-rc1-4-g321459439 ("cat-file: support --textconv/--filters in batch mode"), t8010-cat-file-filters.sh has been failing on Cygwin. Digging into this, the test looks to expose a timing window: it appears that if `git cat-file --textconv --batch` receives input on stdin too quickly, it fails to parse some of that input.

Compare the following output, run from the t8010 trash directory after a failed test run, where adding a `sleep` between the two lines of input changes the output:

    $ { echo $sha1 hello.txt ; echo $sha1 hello; } | git -c diff.txt.textconv='tr A-Za-z N-ZA-Mn-za-m <' cat-file --textconv --batch
    ce013625030ba8dba906f756967f9e9ca394464a blob 6
    uryyb
    $ { echo $sha1 hello.txt ; sleep 1; echo $sha1 hello; } | git -c diff.txt.textconv='tr A-Za-z N-ZA-Mn-za-m <' cat-file --textconv --batch
    ce013625030ba8dba906f756967f9e9ca394464a blob 6
    uryyb
    ce013625030ba8dba906f756967f9e9ca394464a blob 6
    hello
Similarly, I can get t8010 to pass with the following patch:
diff --git a/t/t8010-cat-file-filters.sh b/t/t8010-cat-file-filters.sh
index d8242e467..3aa1385ad 100755
--- a/t/t8010-cat-file-filters.sh
+++ b/t/t8010-cat-file-filters.sh
@@ -54,7 +54,7 @@
 test_expect_success 'cat-file --textconv --batch works' '
 	sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
 	test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&
-	printf "%s hello.txt\n%s hello\n" $sha1 $sha1 |
+	{ printf "%s hello.txt\n" $sha1 && sleep 1 && printf "%s hello\n" $sha1; } |
 	git cat-file --textconv --batch >actual &&
 	printf "%s blob 6\nuryyb\r\n\n%s blob 6\nhello\n\n" \
 		$sha1 $sha1 >expect &&

I don't think blindly applying the patch is the solution here, however.
The correct solution is presumably to work out what is causing cat-file
to discard some of its input and to get it to stop doing that.

(For reference, to get the output above the test was run on the current
master branch, specifically v2.14.1-326-g3dc57ebfb, while the local
installed Git version was v2.14.0, although this behaviour seems to be
consistent since the originating commit.)
Next: Jeff King
Message 1 of 11 in “cat-file timing window on Cygwin”
  1. Adam DinwoodieAug 25, 2017
  2. Jeff KingAug 25, 2017
  3. Ramsay JonesAug 26, 2017
  4. Adam DinwoodieAug 26, 2017
  5. Jeff KingAug 26, 2017
  6. Adam DinwoodieAug 26, 2017
  7. Ramsay JonesAug 27, 2017
  8. Adam DinwoodieAug 27, 2017
  9. Ramsay JonesAug 27, 2017
  10. Jason PyeronAug 27, 2017
  11. Ramsay JonesSep 8, 2017

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.