Skip to content

Commit 78b6601

Browse files
carenasgitster
authored andcommitted
daemon: correctly handle soft accept() errors in service_loop
Since df076bd ([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 to retry with the same listener socket that failed originally. To avoid an unlikely busy loop, fallback to the old behaviour after a couple of attempts. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Acked-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb3b403 commit 78b6601

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

daemon.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,19 @@ static int service_loop(struct socketlist *socklist)
11531153
#endif
11541154
} ss;
11551155
socklen_t sslen = sizeof(ss);
1156-
int incoming = accept(pfd[i].fd, &ss.sa, &sslen);
1156+
int incoming;
1157+
int retry = 3;
1158+
1159+
redo:
1160+
incoming = accept(pfd[i].fd, &ss.sa, &sslen);
11571161
if (incoming < 0) {
11581162
switch (errno) {
1159-
case EAGAIN:
11601163
case EINTR:
1164+
if (--retry)
1165+
goto redo;
1166+
1167+
/* fallthrough */
1168+
case EAGAIN:
11611169
case ECONNABORTED:
11621170
continue;
11631171
default:

0 commit comments

Comments
 (0)