]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: Add --retry-connrefused
authorDaniel Hwang <gnawhleinad@github.com>
Sun, 9 Oct 2016 23:00:25 +0000 (16:00 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 11 Nov 2016 09:00:54 +0000 (10:00 +0100)
to consider ECONNREFUSED as a transient error.

Closes #1064

docs/curl.1
src/tool_cfgable.h
src/tool_getparam.c
src/tool_help.c
src/tool_operate.c

index bc0612f0cd39de01c51ccea4cf389bfbfbe3dd5c..8434d6b7a239e456e746720c8087900a458d1acd 100644 (file)
@@ -1620,6 +1620,10 @@ also \fI--retry-max-time\fP to limit the total time allowed for
 retries. (Added in 7.12.3)
 
 If this option is used several times, the last one will be used.
+.IP "--retry-connrefused"
+In addition to the other conditions, consider ECONNREFUSED as a transient
+error too for \fI--retry\fP. This option is used together with
+\fI--retry\fP. (Added in 7.52.0)
 .IP "--retry-delay <seconds>"
 Make curl sleep this amount of time before each retry when a transfer has
 failed with a transient error (it changes the default backoff time algorithm
index aa98fced5badb272db1f63c9c0b1b4d7eefafada..9f4dbba8c2569cb7d67cb299a235738dfa5f5acd 100644 (file)
@@ -176,6 +176,7 @@ struct OperationConfig {
   bool tcp_nodelay;
   bool tcp_fastopen;
   long req_retry;           /* number of retries */
+  bool retry_connrefused;   /* set connection refused as a transient error */
   long retry_delay;         /* delay between retries (in seconds) */
   long retry_maxtime;       /* maximum time to keep retrying */
 
index 2d16e066d3b6dd632d70fcd53efbd8f41d357385..d1888a2aba7db7c3b9d7b3e656884d4edfaf94ff 100644 (file)
@@ -125,6 +125,7 @@ static const struct LongShort aliases[]= {
   {"$e", "proxy-digest",             FALSE},
   {"$f", "proxy-basic",              FALSE},
   {"$g", "retry",                    TRUE},
+  {"$V", "retry-connrefused",        FALSE},
   {"$h", "retry-delay",              TRUE},
   {"$i", "retry-max-time",           TRUE},
   {"$k", "proxy-negotiate",          FALSE},
@@ -793,6 +794,9 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
         if(err)
           return err;
         break;
+      case 'V': /* --retry-connrefused */
+        config->retry_connrefused = toggle;
+        break;
       case 'h': /* --retry-delay */
         err = str2unum(&config->retry_delay, nextarg);
         if(err)
index 9890cc83b5b5b08df1596554bb296c1bdc1d1266..f4d648c01b4854ccd696964c5982264bfb6ef331 100644 (file)
@@ -198,6 +198,8 @@ static const char *const helptext[] = {
   "     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS",
   "     --retry NUM   "
   "Retry request NUM times if transient problems occur",
+  "     --retry-connrefused  "
+  "Consider \"connection refused\" a transient error",
   "     --retry-delay SECONDS  Wait SECONDS between retries",
   "     --retry-max-time SECONDS  Retry only within this period",
   "     --sasl-ir       Enable initial response in SASL authentication",
index deae87753cf1fabd4bf654b6381b36d7a3d8da42..d467b0df50ddb076668d8ab8d35ffe01477b41d1 100644 (file)
@@ -1441,6 +1441,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
             enum {
               RETRY_NO,
               RETRY_TIMEOUT,
+              RETRY_CONNREFUSED,
               RETRY_HTTP,
               RETRY_FTP,
               RETRY_LAST /* not used */
@@ -1452,6 +1453,13 @@ static CURLcode operate_do(struct GlobalConfig *global,
                (CURLE_FTP_ACCEPT_TIMEOUT == result))
               /* retry timeout always */
               retry = RETRY_TIMEOUT;
+            else if(config->retry_connrefused &&
+                    (CURLE_COULDNT_CONNECT == result)) {
+              long oserrno;
+              curl_easy_getinfo(curl, CURLINFO_OS_ERRNO, &oserrno);
+              if(ECONNREFUSED == oserrno)
+                retry = RETRY_CONNREFUSED;
+            }
             else if((CURLE_OK == result) ||
                     (config->failonerror &&
                      (CURLE_HTTP_RETURNED_ERROR == result))) {
@@ -1499,7 +1507,11 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
             if(retry) {
               static const char * const m[]={
-                NULL, "timeout", "HTTP error", "FTP error"
+                NULL,
+                "timeout",
+                "connection refused",
+                "HTTP error",
+                "FTP error"
               };
 
               warnf(config->global, "Transient problem: %s "