Fix invalid "Network is unreachable" errors#794
Closed
antlarr wants to merge 2 commits intocurl:masterfrom
Closed
Conversation
Sometimes, in systems with both ipv4 and ipv6 addresses but where the network doesn't support ipv6, Curl_is_connected returns an error (intermittently) even if the ipv4 socket connects successfully. This happens because there's a for-loop that iterates on the sockets but the error variable is not resetted when the ipv4 is checked and is ok. This patch fixes this problem by setting error to 0 when checking the second socket and not having a result yet.
Member
|
Ref: https://curl.haxx.se/mail/lib-2016-05/0019.html We use that variable later on though and I think in that case we don't want to reset it diff --git a/lib/connect.c b/lib/connect.c
index 8dfe9e2..39fd064 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -722,7 +722,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
struct SessionHandle *data = conn->data;
CURLcode result = CURLE_OK;
long allow;
- int error = 0;
+ int error_save = 0;
struct timeval now;
int rc;
int i;
@@ -749,6 +749,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
}
for(i=0; i<2; i++) {
+ int error = 0;
const int other = i ^ 1;
if(conn->tempsock[i] == CURL_SOCKET_BAD)
continue;
@@ -817,6 +818,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
* address" for the given host. But first remember the latest error.
*/
if(error) {
+ error_save = error;
data->state.os_errno = error;
SET_SOCKERRNO(error);
if(conn->tempaddr[i]) {
@@ -859,7 +861,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
hostname = conn->host.name;
failf(data, "Failed to connect to %s port %ld: %s",
- hostname, conn->port, Curl_strerror(conn, error));
+ hostname, conn->port, Curl_strerror(conn, error_save));
}
return result; |
We use the error variable later on though and in that case we don't want to reset it. As suggested by Jay Satiro on curl#794
Member
|
I took another look at this just now and it seems that with your patch there's no path for what I thought could happen to actually happen. |
Contributor
Author
|
I thought so, but just in case I commited your patch too. Should I revert it? |
Member
|
No need, I'll just merge the first patch and leave out the second one. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sometimes, in systems with both ipv4 and ipv6 addresses but where the
network doesn't support ipv6, Curl_is_connected returns an error
(intermittently) even if the ipv4 socket connects successfully.
This happens because there's a for-loop that iterates on the sockets
but the error variable is not resetted when the ipv4 is checked and
is ok.
This patch fixes this problem by setting error to 0 when checking the
second socket and not having a result yet.