Skip to content

Commit afbdcd4

Browse files
committed
libfetch: Fail hard if interrupted while connecting
This fixes an issue where the first address that DNS returns is blocked by a packet filter, so we hang for a while, then the user hits Ctrl-C, interrupting connect(2), whereupon we move on to the next address, get a connection, request the file, and return to fetch(1), which sees that SIGINT was caught and bails. Note that we make no attempt to enforce fetchTimeout in the connection phase, and never have. It's feasible, but non-trivial, so we'll leave it as an exercise for future us. PR: 293312 MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D55406
1 parent 1b7c4d2 commit afbdcd4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/libfetch/common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,13 @@ fetch_connect(const char *host, int port, int af, int verbose)
651651
goto syserr;
652652
}
653653
/* attempt to connect to server address */
654-
if ((err = connect(sd, sai->ai_addr, sai->ai_addrlen)) == 0)
654+
while ((err = connect(sd, sai->ai_addr, sai->ai_addrlen)) < 0) {
655+
if (errno == EINTR && fetchRestartCalls)
656+
continue;
657+
break;
658+
}
659+
/* success? */
660+
if (err == 0)
655661
break;
656662
/* clean up before next attempt */
657663
close(sd);

0 commit comments

Comments
 (0)