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

[PATCH v2 0/1] Fix t5516 flakiness in Visual Studio builds

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 29, 2019, 13:37 UTC
Message-ID
<pull.428.v2.git.1572356272.gitgitgadget@gmail.com>
In-Reply-To
<pull.428.git.1572274859.gitgitgadget@gmail.com>

Among the flaky tests, it seems that the Azure Pipeline suffers relatively frequently from t5516 failing with the Visual Studio builds. Essentially, we grep for an error message, but that error message is produced twice, once by a fetch and once by the upload-pack spawned from it, and those error messages are usually interleaved because of MSVC runtime fprintf() idiosyncracies.

The commit message of this patch is based, in part, on https://github.com/gitgitgadget/git/pull/407. The patch itself is a much more minimal alternative (using xwrite() instead of fprintf()) to the code of https://github.com/gitgitgadget/git/pull/407, avoiding the complexity of the part of the code that allows for unlimited messages.

While it would seem theoretically more elegant to allow for unlimited messages, in practice too-long messages cause more problems than they solve, and therefore we already clip them, and this patch does not change that behavior.

This fixes https://github.com/gitgitgadget/git/issues/240.
Changes since v1:
 * Changed the oneline to be more accurate (thanks Junio).
 * Improved the commit message (e.g. talking about the xwrite() function
   this patch uses, rather than the write_in_full() function used by an
   earlier iteration, thanks Gábor).
 * Revamped the actual code to account for insanely long prefixes (thanks
   for the advice, Junio).
Johannes Schindelin (1):
  vreportf(): avoid relying on stdio buffering
 usage.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
base-commit: 566a1439f6f56c2171b8853ddbca0ad3f5098770
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-428%2Fdscho%2Ffix-t5516-flakiness-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-428/dscho/fix-t5516-flakiness-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/428
Range-diff vs v1:
 1:  455026ce3e ! 1:  e426627e14 vreportf(): avoid buffered write in favor of unbuffered one
     @@ -1,6 +1,6 @@
      Author: Johannes Schindelin <johannes.schindelin@gmx.de>
      
     -    vreportf(): avoid buffered write in favor of unbuffered one
     +    vreportf(): avoid relying on stdio buffering
      
          The MSVC runtime behavior differs from glibc's with respect to
          `fprintf(stderr, ...)` in that the former writes out the message
     @@ -16,7 +16,9 @@
          Let's avoid this predicament altogether by rendering the entire message,
          including the prefix and the trailing newline, into the buffer we
          already have (and which is still fixed size) and then write it out via
     -    `write_in_full()`.
     +    `xwrite()`.
     +
     +    We still clip the message to at most 4095 characters.
      
          The history of `vreportf()` with regard to this issue includes the
          following commits:
     @@ -36,39 +38,45 @@
                                  so it's safe to use xwrite() again
          5e5be9e2 (2016-06-28) - recv_sideband() uses xwrite() again
      
     -    Note that we need to be careful to handle the return value of
     -    `vsnprintf()` that indicates the _desired_ byte count.
     +    Note that we print nothing if the `vsnprintf()` call failed to render
     +    the error message; There is little we can do in that case, and it should
     +    not happen anyway.
      
          Also please note that we `fflush(stderr)` here to help when running in a
          Git Bash on Windows: in this case, `stderr` is not actually truly
          unbuffered, and needs the extra help.
      
     -    Co-authored-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
     +    Helped-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
     +    Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
     +    Helped-by: Junio C Hamano <gitster@pobox.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       diff --git a/usage.c b/usage.c
       --- a/usage.c
       +++ b/usage.c
      @@
     + void vreportf(const char *prefix, const char *err, va_list params)
       {
       	char msg[4096];
     - 	char *p;
     --
     --	vsnprintf(msg, sizeof(msg), err, params);
     +-	char *p;
      +	size_t off = strlcpy(msg, prefix, sizeof(msg));
     -+	int ret = vsnprintf(msg + off, sizeof(msg) - off, err, params);
     - 	for (p = msg; *p; p++) {
     ++	char *p, *pend = msg + sizeof(msg);
     + 
     +-	vsnprintf(msg, sizeof(msg), err, params);
     +-	for (p = msg; *p; p++) {
     ++	p = msg + off < pend ? msg + off : pend - 1;
     ++	if (vsnprintf(p, pend - p, err, params) < 0)
     ++		return; /* vsnprintf() failed, there is nothing we can do */
     ++
     ++	for (; p != pend - 1 && *p; p++) {
       		if (iscntrl(*p) && *p != '\t' && *p != '\n')
       			*p = '?';
       	}
      -	fprintf(stderr, "%s%s\n", prefix, msg);
     -+	if (ret > 0) {
     -+		if (off + ret > sizeof(msg) - 1)
     -+			ret = sizeof(msg) - 1 - off;
     -+		msg[off + ret] = '\n'; /* we no longer need a NUL */
     -+		fflush(stderr);
     -+		xwrite(2, msg, off + ret + 1);
     -+	}
     ++
     ++	*(p++) = '\n'; /* we no longer need a NUL */
     ++	fflush(stderr);
     ++	xwrite(2, msg, p - msg);
       }
       
       static NORETURN void usage_builtin(const char *err, va_list params)
-- 
gitgitgadget
Previous: Johannes SchindelinNext: Johannes Schindelin via GitGitGadget
Message 15 of 34 in “Fix t5516 flakiness in Visual Studio builds”
  1. 0/1 Fix t5516 flakiness in Visual Studio buildsJohannes Schindelin via GitGitGadget, Oct 28, 2019
  2. 1/1 vreportf(): avoid buffered write in favor of unbuffered oneJohannes Schindelin via GitGitGadget, Oct 28, 2019
  3. Junio C HamanoOct 29, 2019
  4. Johannes SchindelinOct 29, 2019
  5. Jeff KingOct 29, 2019
  6. Johannes SchindelinOct 29, 2019
  7. Jeff KingOct 29, 2019
  8. Johannes SchindelinOct 29, 2019
  9. Junio C HamanoOct 30, 2019
  10. Junio C HamanoOct 29, 2019
  11. SZEDER GáborOct 29, 2019
  12. Johannes SchindelinOct 29, 2019
  13. Jeff KingOct 29, 2019
  14. Johannes SchindelinOct 29, 2019
  15. 0/1 Fix t5516 flakiness in Visual Studio buildsJohannes Schindelin via GitGitGadget, Oct 29, 2019
  16. 1/1 vreportf(): avoid relying on stdio bufferingJohannes Schindelin via GitGitGadget, Oct 29, 2019
  17. Alexandr MiloslavskiyOct 29, 2019
  18. Johannes SchindelinOct 29, 2019
  19. Jeff KingOct 29, 2019
  20. Alexandr MiloslavskiyOct 29, 2019
  21. Alexandr MiloslavskiyOct 29, 2019
  22. 0/1 Fix t5516 flakiness in Visual Studio buildsJohannes Schindelin via GitGitGadget, Oct 29, 2019
  23. 1/1 vreportf(): avoid relying on stdio bufferingJohannes Schindelin via GitGitGadget, Oct 29, 2019
  24. Jeff KingOct 29, 2019
  25. Johannes SchindelinOct 30, 2019
  26. Jeff KingOct 31, 2019
  27. Johannes SchindelinOct 31, 2019
  28. Jeff KingOct 31, 2019
  29. Johannes SchindelinNov 1, 2019
  30. Junio C HamanoOct 30, 2019
  31. Johannes SchindelinOct 30, 2019
  32. 0/1 Fix t5516 flakiness in Visual Studio buildsJohannes Schindelin via GitGitGadget, Oct 30, 2019
  33. 1/1 vreportf(): avoid relying on stdio bufferingJohannes Schindelin via GitGitGadget, Oct 30, 2019
  34. Junio C HamanoNov 2, 2019

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.