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

Re: [PATCH] Only print an error for the last connect() failure

From
Dave Zarzycki <zarzycki@apple.com>
Date
Jun 9, 2011, 16:49 UTC
Message-ID
<767D7D04-6089-4C7B-A532-C5EC9FE0CCC6@apple.com>
In-Reply-To
<20110609163340.GD25885@sigill.intra.peff.net>
On Jun 9, 2011, at 9:33 AM, Jeff King wrote:
Show 48 quoted lines
> On Thu, Jun 09, 2011 at 09:18:10AM -0700, Dave Zarzycki wrote:
> 
>> IPv6 hosts are often unreachable on the primarily IPv4 Internet and
>> therefore we shouldn't print an error if there are still other hosts we
>> can try to connect() to. This helps "git fetch --quiet" stay quiet.
>> ---
>> connect.c |   12 +++++++-----
>> 1 files changed, 7 insertions(+), 5 deletions(-)
>> 
>> diff --git a/connect.c b/connect.c
>> index 2119c3f..7f70ce7 100644
>> --- a/connect.c
>> +++ b/connect.c
>> @@ -225,11 +225,13 @@ static int git_tcp_connect_sock(char *host, int flags)
>> 		}
>> 		if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
>> 			saved_errno = errno;
>> -			fprintf(stderr, "%s[%d: %s]: errno=%s\n",
>> -				host,
>> -				cnt,
>> -				ai_name(ai),
>> -				strerror(saved_errno));
>> +			if (ai->ai_next == NULL) {
>> +				fprintf(stderr, "%s[%d: %s]: errno=%s\n",
>> +					host,
>> +					cnt,
>> +					ai_name(ai),
>> +					strerror(saved_errno));
>> +			}
> 
> I agree being noisy about early failures when we succeed later is a bad
> thing. But when we fail completely, doesn't your code now mask early
> failures and print only the final one? The early failures might be the
> important ones for the user.
> 
> So perhaps we should do something instead like:
> 
>  struct strbuf error_message = STRBUF_INIT;
>  ...
>  if (connect(...) < 0) {
>          strbuf_addf(&error_message, "%s[%d: %s]: errno=%s\n",
>                      host, cnt, ai_name(ai), strerror(errno));
>          ...
>  }
> 
>  if (sockfd < 0)
>          die("unable to connect to %s:\n%s", host, error_message.buf);
>  strbuf_release(&error_message);
I'm happy to make that change.
Personally speaking, I don't think we're masking failures any more than git is masking failures when it doesn't find a ref in .git/refs and it falls back to .git/packed-refs. This fallback is by design, and the same is true of any classic loop around getaddrinfo(). Of course, reasonable people may disagree about what the "right" thing to do here is. :-)
In any case, I'll update the patch later today.
davez
Previous: Jeff KingNext: Jeff King
Message 3 of 5 in “Only print an error for the last connect() failure”
  1. Only print an error for the last connect() failureDave Zarzycki, Jun 9, 2011
  2. Jeff KingJun 9, 2011
  3. Dave ZarzyckiJun 9, 2011
  4. Jeff KingJun 9, 2011
  5. Junio C HamanoJun 9, 2011

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.