From 0421607c000fae5a09532725e06f5dbc56fd22cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 17 Sep 2023 17:13:18 +0200 Subject: [PATCH] Fix HTTP connect on linux (need to ignore failed connections in the select) --- Common/Net/HTTPClient.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 5a8e12f7ee..449251100b 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -117,7 +117,13 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { fd_util::SetNonBlocking(sock, true); // Start trying to connect (async with timeout.) - connect(sock, possible->ai_addr, (int)possible->ai_addrlen); + errno = 0; + if (connect(sock, possible->ai_addr, (int)possible->ai_addrlen) < 0) { + if (errno != EINPROGRESS) { + ERROR_LOG(HTTP, "connect(%d) call failed (%d: %s)", sock, errno, strerror(errno)); + continue; + } + } sockets.push_back(sock); FD_SET(sock, &fds); if (maxfd < sock + 1) { @@ -125,6 +131,11 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { } } + if (sockets.empty()) { + ERROR_LOG(HTTP, "No resolved address would connect!"); + // TODO: What do we do here? + } + int selectResult = 0; long timeoutHalfSeconds = floor(2 * timeout); while (timeoutHalfSeconds >= 0 && selectResult == 0) {