]> granicus.if.org Git - curl/commitdiff
connect: fix race condition with happy eyeballs timeout
authorAnders Bakken <agbakken@gmail.com>
Thu, 28 Sep 2017 15:20:04 +0000 (08:20 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 29 Sep 2017 06:51:59 +0000 (08:51 +0200)
The timer should be started after conn->connecttime is set. Otherwise
the timer could expire without this condition being true:

    /* should we try another protocol family? */
    if(i == 0 && conn->tempaddr[1] == NULL &&
      curlx_tvdiff(now, conn->connecttime) >= HAPPY_EYEBALLS_TIMEOUT) {

Ref: #1928

lib/connect.c

index 42559f97948facc1a199061df669a79cd2828ef3..b7d10af5536240d3ccafc4f29328239e67046430 100755 (executable)
@@ -1161,7 +1161,6 @@ CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
   conn->tempaddr[1] = NULL;
   conn->tempsock[0] = CURL_SOCKET_BAD;
   conn->tempsock[1] = CURL_SOCKET_BAD;
-  Curl_expire(conn->data, HAPPY_EYEBALLS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS);
 
   /* Max time for the next connection attempt */
   conn->timeoutms_per_addr =
@@ -1182,6 +1181,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
   }
 
   data->info.numconnects++; /* to track the number of connections made */
+  Curl_expire(conn->data, HAPPY_EYEBALLS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS);
 
   return CURLE_OK;
 }