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

Re: [PATCH v2] daemon: correctly handle soft accept() errors in service_loop

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Jun 27, 2025, 23:05 UTC
Message-ID
<vgailqqh3bcip3gxtdffoo4ey7xjso4xerewxncy22shrzn4k2@25hst4sfgxq4>
In-Reply-To
<xmqq34bl7xa1.fsf@gitster.g>
On Fri, Jun 27, 2025 at 01:19:18PM -0800, Junio C Hamano wrote:
Show 43 quoted lines
> Carlo Marcelo Arenas Belón <carenas@gmail.com> writes:
> 
> > On Fri, Jun 27, 2025 at 09:38:47AM -0800, Phillip Wood wrote:
> >> 
> >> On 26/06/2025 18:21, Carlo Marcelo Arenas Belón wrote:
> >> > 
> >> > diff --git a/daemon.c b/daemon.c
> >> > index d1be61fd57..f113839781 100644
> >> > --- a/daemon.c
> >> > +++ b/daemon.c
> >> > @@ -1145,6 +1145,7 @@ static int service_loop(struct socketlist *socklist)
> >> >   		for (size_t i = 0; i < socklist->nr; i++) {
> >> >   			if (pfd[i].revents & POLLIN) {
> >> > +				int incoming;
> >> >   				union {
> >> >   					struct sockaddr sa;
> >> >   					struct sockaddr_in sai;
> >> > @@ -1153,11 +1154,19 @@ static int service_loop(struct socketlist *socklist)
> >> >   #endif
> >> >   				} ss;
> >> >   				socklen_t sslen = sizeof(ss);
> >> > -				int incoming = accept(pfd[i].fd, &ss.sa, &sslen);
> >> 
> >> Why is the declaration of incoming moved but retry is declared here?
> >
> > Separating the declaration and assignment for incoming is needed so we can
> > insert a label for goto; moving it up just removes distractions so the rest
> > of the logic is clearly in view.
> >
> > Obviously that includes the definition and assignment for retry.
> >
> > How would you suggest to arrange this better?
> 
> I think what Phillip meant was more like this, perhaps.
> 
> 		socklen_t sslen = sizeof(ss);
> -		int incoming = accept(pfd[i].fd, &ss.sa, &sslen);
> +		int incoming;
> +		int retry = 3;
> +
> +		incoming = accept(pfd[i].fd, &ss.sa, &sslen);
> 		if (incoming < 0) {
> 			...

That seems unnecessarily restrictive just to minimize churn and leaves the deflaration of incoming strangely sitting in between two assignments, which while it doesn't trigger -Wdeclaration-after-statement seems to go against its spirit.

Will include in a v3 with all other suggestions, but frankly think that the original was overall cleaner.

Carlo
Previous: Junio C HamanoNext: Hridoy Ahmed
Message 7 of 14 in “daemon: correctly handle soft accept() errors”
  1. daemon: correctly handle soft accept() errorsCarlo Marcelo Arenas Belón, Jun 26, 2025
  2. Kristoffer HaugsbakkJun 26, 2025
  3. daemon: correctly handle soft accept() errors in service_loopCarlo Marcelo Arenas Belón, Jun 26, 2025
  4. Phillip WoodJun 27, 2025
  5. Carlo Marcelo Arenas BelónJun 27, 2025
  6. Junio C HamanoJun 27, 2025
  7. Carlo Marcelo Arenas BelónJun 27, 2025
  8. Hridoy AhmedJun 27, 2025
  9. Junio C HamanoJun 27, 2025
  10. Phillip WoodJun 30, 2025
  11. daemon: correctly handle soft accept() errors in service_loopCarlo Marcelo Arenas Belón, Jun 27, 2025
  12. Phillip WoodJun 30, 2025
  13. Junio C HamanoJun 30, 2025
  14. Phillip WoodJul 1, 2025

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.