archive mirror
 help / color / mirror / Atom feed
From: Alexandr Miloslavskiy <>
To: Johannes Schindelin <>,
	Alexandr Miloslavskiy via GitGitGadget  <>
Cc:, Junio C Hamano <>
Subject: Re: [PATCH v2 1/1] vreportf: Fix interleaving issues, remove 4096 limitation
Date: Fri, 25 Oct 2019 14:38:43 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

> Maybe this could do with an example?

I myself observed results like this when running t5516:
fatal: git fatal: remote errouploar: upload-pack: not our ref 
64ea4c133d59fa98e86a771eda009872d6ab2886d-pack: not o
ur ref 64ea4c133d59fa98e86a771eda009872d6ab2886

Do you want me to add this garbled string to commit message?

>> +static void replace_control_chars(char* str, size_t size, char replacement)

> So this is just factored out from `vreportf()`, right?


>> +	buf = malloc(buf_size);

> Why not `alloca()`?

Allocating large chunks on stack is usually not recommended. There is a 
funny test "init allows insanely long --template" in t0001 which 
demonstrates that sometimes vreportf() can attempt to print very long 
strings. Crashing due to stack overflow doesn't sound like a good thing.

> And to take a step back, I think that previous rounds of patches trying
> to essentially address the same problem made the case that it is okay to
> cut off insanely-long messages, so I am not sure we would want to open
> that can of worms again...

I draw a different conclusion here. Each author thought that "1024 must 
definitely be enough!" but then discovered that it's not enough again, 
for example due to long "usage" output. At some point, f4c3edc0 even 
tried to remove all limits after a chain of limits that were too small. 
So I would say that this is still a problem.

> Quite honestly, I would love to avoid that amount of complexity,
> certainly in a part of the code that we would like to have rock solid
> because it is usually exercised when things go very, very wrong and we
> need to provide the user who is bitten by it enough information to take
> to the Git contributors to figure out the root cause(s).

It's a choice between simpler code and trying to account for everything 
that could happen. I think we'd rather have more complex code that 
handles more cases, exactly to try and deliver output to user no matter 

> Is the problem that causes those failures with VS the fact that
> `fprintf(stderr, ...)` might be interleaved with the output of another
> process that _also_ wants to write to `stderr`? I assume that this _is_
> the problem.

This is where I started. But if you look at comment in vreportf_buf, 
there are more problems, such as interleaving blocks of larger messages, 
which could happen on any platform. I tried to make it work in most 
cases possible.

> Further, I guess that the problem is compounded by the fact that we
> usually run the tests in a Git Bash on Windows, i.e. in a MinTTY that
> emulates a console (there _is_ work under way to support the newly
> introduces ptys, but that work is far from done), so the standard error
> file handle might behave in unexpected ways in that scenario.

To my knowledge, this is not related. t5516 failures are because git 
explicitly wants stderr to be unbuffered. VC++ and MinGW runtimes take 
that literally. fprintf() outputs char-by-char, and all of that results 
in char-interleaving.

> But I do wonder whether replacing that `fprintf()` by a `write()` would
> work better. After all, we could write the `prefix` into the `msg`
> already:
> 	size_t off = strlcpy(msg, prefix, sizeof(msg));
> 	int ret = vsnprintf(msg + off, sizeof(msg) - off, err, params);
> 	[...]
> 	if (ret > 0)
> 		write(2, msg, off + ret);
> Would that also work around the problem?

You forgot to add '\'n. But yes, that would solve many problems, except 
truncation to 4096. Then I would expect a patch to increase buffer size 
to 8192 in the next couple years. And if you also try to solve 
truncation, it will get you very close to my code.

  reply	other threads:[~2019-10-25 12:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 14:39 [PATCH 0/1] vreportf: Fix interleaving issues, remove 4096 limitation Alexandr Miloslavskiy via GitGitGadget
2019-10-22 14:39 ` [PATCH 1/1] " Alexandr Miloslavskiy via GitGitGadget
2019-10-22 14:45 ` [PATCH v2 0/1] " Alexandr Miloslavskiy via GitGitGadget
2019-10-22 14:45   ` [PATCH v2 1/1] " Alexandr Miloslavskiy via GitGitGadget
2019-10-25 11:37     ` Johannes Schindelin
2019-10-25 12:38       ` Alexandr Miloslavskiy [this message]
2019-10-25 14:02         ` Johannes Schindelin
2019-10-25 14:15           ` Alexandr Miloslavskiy
2019-10-25 21:28             ` Johannes Schindelin
2019-10-25 22:11           ` Jeff King
2019-10-26  8:02             ` Alexandr Miloslavskiy
2019-10-26 20:56             ` Johannes Schindelin
2019-10-26 21:36               ` Jeff King
2019-10-28 16:05                 ` Johannes Schindelin
2019-10-26 21:56               ` Johannes Schindelin
2019-10-26 22:05                 ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).