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

Re: [PATCH v2 1/3] sideband: avoid reporting incomplete sideband messages

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 20, 2020, 20:33 UTC
Message-ID
<xmqqwnzkab85.fsf@gitster.c.googlers.com>
In-Reply-To
<e4ba96358b7c5d2b4148c5529a3c253dc0d1f358.1603136143.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 27 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> In 2b695ecd74d (t5500: count objects through stderr, not trace,
> 2020-05-06) we tried to ensure that the "Total 3" message could be
> grepped in Git's output, even if it sometimes got chopped up into
> multiple lines in the trace machinery.
> ...
> The correct way to fix this is to return from `demultiplex_sideband()`
> early. The caller will then write out the contents of the primary packet
> and continue looping. The `scratch` buffer for incomplete sideband
> messages is owned by that caller, and will continue to accumulate the
> remainder(s) of those messages. The loop will only end once
> `demultiplex_sideband()` returned non-zero _and_ did not indicate a
> primary packet, which is the case only when we hit the `cleanup:` path,
> in which we take care of flushing any unfinished sideband messages and
> release the `scratch` buffer.
>
> To ensure that this does not get broken again, we introduce a pair of
> subcommands of the `pkt-line` test helper that specifically chop up the
> sideband message and squeeze a primary packet into the middle.
>
> Final note: The other test case touched by 2b695ecd74d (t5500: count
> objects through stderr, not trace, 2020-05-06) is not affected by this
> issue because the sideband machinery is not involved there.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---

Nicely explained. Do we want to also give credit to Peff for the single-liner fix here, perhaps with a suggested/helped-by trailer?

Show 18 quoted lines
>  sideband.c               |  2 +-
>  t/helper/test-pkt-line.c | 23 +++++++++++++++++++++++
>  t/t0070-fundamental.sh   |  6 ++++++
>  3 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/sideband.c b/sideband.c
> index 0a60662fa6..a5405b9aaa 100644
> --- a/sideband.c
> +++ b/sideband.c
> @@ -190,7 +190,7 @@ int demultiplex_sideband(const char *me, char *buf, int len,
>  		return 0;
>  	case 1:
>  		*sideband_type = SIDEBAND_PRIMARY;
> -		break;
> +		return 1;
>  	default:
>  		strbuf_addf(scratch, "%s%s: protocol error: bad band #%d",
>  			    scratch->len ? "\n" : "", me, band);
Show 21 quoted lines
> diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
> index 69152958e5..0bf20642be 100644
> --- a/t/helper/test-pkt-line.c
> +++ b/t/helper/test-pkt-line.c
> @@ -84,6 +84,25 @@ static void unpack_sideband(void)
>  	}
>  }
>  
> +static int send_split_sideband(void)
> +{
> +	const char *part1 = "Hello,";
> +	const char *primary = "\001primary: regular output\n";
> +	const char *part2 = " world!\n";
> +
> +	send_sideband(1, 2, part1, strlen(part1), LARGE_PACKET_MAX);
> +	packet_write(1, primary, strlen(primary));
> +	send_sideband(1, 2, part2, strlen(part2), LARGE_PACKET_MAX);
> +	packet_response_end(1);
> +
> +	return 0;
> +}
OK.
Show 34 quoted lines
> +static int receive_sideband(void)
> +{
> +	return recv_sideband("sideband: ", 0, 1);
> +}
> +
>  int cmd__pkt_line(int argc, const char **argv)
>  {
>  	if (argc < 2)
> @@ -95,6 +114,10 @@ int cmd__pkt_line(int argc, const char **argv)
>  		unpack();
>  	else if (!strcmp(argv[1], "unpack-sideband"))
>  		unpack_sideband();
> +	else if (!strcmp(argv[1], "send-split-sideband"))
> +		send_split_sideband();
> +	else if (!strcmp(argv[1], "receive-sideband"))
> +		receive_sideband();
>  	else
>  		die("invalid argument '%s'", argv[1]);
>  
> diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
> index 7b111a56fd..357201640a 100755
> --- a/t/t0070-fundamental.sh
> +++ b/t/t0070-fundamental.sh
> @@ -34,4 +34,10 @@ test_expect_success 'check for a bug in the regex routines' '
>  	test-tool regex --bug
>  '
>  
> +test_expect_success 'incomplete sideband messages are reassembled' '
> +	test-tool pkt-line send-split-sideband >split-sideband &&
> +	test-tool pkt-line receive-sideband <split-sideband 2>err &&
> +	grep "Hello, world" err
> +'
> +
>  test_done
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 10 of 33 in “t5500.43: make the check a bit more robust”
  1. t5500.43: make the check a bit more robustJohannes Schindelin via GitGitGadget, Oct 13, 2020
  2. Junio C HamanoOct 13, 2020
  3. Jeff KingOct 13, 2020
  4. Junio C HamanoOct 13, 2020
  5. Jeff KingOct 13, 2020
  6. Johannes SchindelinOct 17, 2020
  7. Johannes SchindelinOct 17, 2020
  8. 0/3 Work around flakiness in t5500.43Johannes Schindelin via GitGitGadget, Oct 19, 2020
  9. 1/3 sideband: avoid reporting incomplete sideband messagesJohannes Schindelin via GitGitGadget, Oct 19, 2020
  10. Junio C HamanoOct 20, 2020
  11. Johannes SchindelinOct 20, 2020
  12. Junio C HamanoOct 20, 2020
  13. 2/3 sideband: report unhandled incomplete sideband messages as bugsJohannes Schindelin via GitGitGadget, Oct 19, 2020
  14. 3/3 sideband: add defense against packets missing a band designatorJohannes Schindelin via GitGitGadget, Oct 19, 2020
  15. Junio C HamanoOct 20, 2020
  16. Jeff KingOct 23, 2020
  17. Junio C HamanoOct 23, 2020
  18. Jeff KingOct 23, 2020
  19. Johannes SchindelinOct 23, 2020
  20. Jeff KingOct 23, 2020
  21. Johannes SchindelinOct 26, 2020
  22. 0/2 Work around flakiness in t5500.43Johannes Schindelin via GitGitGadget, Oct 26, 2020
  23. 1/2 sideband: avoid reporting incomplete sideband messagesJohannes Schindelin via GitGitGadget, Oct 26, 2020
  24. 2/2 sideband: report unhandled incomplete sideband messages as bugsJohannes Schindelin via GitGitGadget, Oct 26, 2020
  25. Junio C HamanoOct 26, 2020
  26. sideband: diagnose more incoming packet anomaliesJeff King, Oct 27, 2020
  27. Jeff KingOct 27, 2020
  28. Junio C HamanoOct 27, 2020
  29. Jeff KingOct 27, 2020
  30. Junio C HamanoOct 27, 2020
  31. Jeff KingOct 28, 2020
  32. Jeff KingOct 27, 2020
  33. Junio C HamanoOct 27, 2020

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.