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
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jun 27, 2025, 08:38 UTC
Message-ID
<08804dbe-56dd-4c0e-b36b-a82768b0aa29@gmail.com>
In-Reply-To
<20250626172159.87204-1-carenas@gmail.com>
Hi Carlo
On 26/06/2025 18:21, Carlo Marcelo Arenas Belón wrote:
Show 9 quoted lines
> Since df076bdbcc ([PATCH] GIT: Listen on IPv6 as well, if available.,
> 2005-07-23), the original error checking was included in an inner loop
> unchanged, where its effect was different.
> 
> Instead of retrying, after a EINTR during accept() in the listening
> socket, it will advance to the next one and try with that instead,
> leaving the client waiting for another round.
> 
> Make sure that the loop doesn't advance
That makes sense
> and while at it, make sure
> that any possible completed children get reaped earlier.

What's the rationale for that? It means we end up calling reap_dead_children() twice which sounds inefficient. If it is important then I'm also struggling to see how it fits in with the proposal to use SA_RESTART

Show 26 quoted lines
> To avoid an
> unlikely busy loop, fallback to the old behaviour after a couple
> of attempts.
> 
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
> ---
>   daemon.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
> 
> 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?
Thanks
Phillip
Show 17 quoted lines
> +				int retry = 3;
> +
> +			redo:
> +				incoming = accept(pfd[i].fd, &ss.sa, &sslen);
>   				if (incoming < 0) {
>   					switch (errno) {
> -					case EAGAIN:
>   					case EINTR:
> +						if (--retry) {
> +							check_dead_children();
> +							goto redo;
> +						}
> +						/* fallthrough */
> +					case EAGAIN:
>   					case ECONNABORTED:
>   						continue;
>   					default:
Previous: Carlo Marcelo Arenas BelónNext: Carlo Marcelo Arenas Belón
Message 4 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.