Paul Marks wrote:
> I then ran this on my router:
> $ iptables -I FORWARD -i eth1 -s 216.218.228.119 -j DROP
> 
> 
> And curl hangs waiting for the IPv4 response:

Here is a fix for this.

-- 
Björn
>From 4ea3b672ce0fe3c1c58fc0bab2b8051c5987e1bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Stenberg?= <[email protected]>
Date: Tue, 29 Oct 2013 14:43:01 +0100
Subject: [PATCH] bugfix: Don't block waiting for socket1 connect.

This patch fixes a bug in Happy Eyeballs where curl would wait for a
connect response from socket1 before checking socket2.

Also, it updates error messages for failed connections, showing the ip
addresses that failed rather than just the host name repeatedly.
---
 lib/connect.c |   25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/lib/connect.c b/lib/connect.c
index 93b2135..2cf1fc0 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -747,9 +747,9 @@ CURLcode Curl_is_connected(struct connectdata *conn,
       if(curlx_tvdiff(now, conn->connecttime) >= conn->timeoutms_per_addr) {
         infof(data, "After %ldms connect time, move on!\n",
               conn->timeoutms_per_addr);
-        break;
+        error = ETIMEDOUT;
       }
-      return CURLE_OK;
+      break;
 
     case CURL_CSELECT_OUT:
       if(verifyconnect(conn->tempsock[i], &error)) {
@@ -802,22 +802,25 @@ CURLcode Curl_is_connected(struct connectdata *conn,
      * address" for the given host. But first remember the latest error.
      */
     if(error) {
+      char ipaddress[MAX_IPADR_LEN];
       data->state.os_errno = error;
       SET_SOCKERRNO(error);
-    }
+      Curl_printable_address(conn->tempaddr[i], ipaddress, MAX_IPADR_LEN);
+      infof(data, "connect to %s port %ld: %s\n",
+            ipaddress, conn->port, Curl_strerror(conn, error));
 
-    conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
-                               allow : allow / 2;
-    code = trynextip(conn, sockindex, i, connected);
+      conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
+                                 allow : allow / 2;
 
-    if(code) {
-      error = SOCKERRNO;
-      data->state.os_errno = error;
-      failf(data, "Failed connect to %s:%ld; %s",
-            conn->host.name, conn->port, Curl_strerror(conn, error));
+      code = trynextip(conn, sockindex, i, connected);
     }
   }
 
+  if(code) {
+    /* no more addresses to try */
+    failf(data, "Failed to connect to %s port %ld: %s",
+          conn->host.name, conn->port, Curl_strerror(conn, error));
+  }
   return code;
 }
 
-- 
1.7.10.4

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to