Commit cdfda3ee authored by Daniel Hwang's avatar Daniel Hwang Committed by Daniel Stenberg
Browse files

curl: Add --retry-connrefused

to consider ECONNREFUSED as a transient error.

Closes #1064
parent ea80a2dc
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -1620,6 +1620,10 @@ also \fI--retry-max-time\fP to limit the total time allowed for
retries. (Added in 7.12.3)
retries. (Added in 7.12.3)


If this option is used several times, the last one will be used.
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>"
.IP "--retry-delay <seconds>"
Make curl sleep this amount of time before each retry when a transfer has
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
failed with a transient error (it changes the default backoff time algorithm
+1 −0
Original line number Original line Diff line number Diff line
@@ -176,6 +176,7 @@ struct OperationConfig {
  bool tcp_nodelay;
  bool tcp_nodelay;
  bool tcp_fastopen;
  bool tcp_fastopen;
  long req_retry;           /* number of retries */
  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_delay;         /* delay between retries (in seconds) */
  long retry_maxtime;       /* maximum time to keep retrying */
  long retry_maxtime;       /* maximum time to keep retrying */


+4 −0
Original line number Original line Diff line number Diff line
@@ -125,6 +125,7 @@ static const struct LongShort aliases[]= {
  {"$e", "proxy-digest",             FALSE},
  {"$e", "proxy-digest",             FALSE},
  {"$f", "proxy-basic",              FALSE},
  {"$f", "proxy-basic",              FALSE},
  {"$g", "retry",                    TRUE},
  {"$g", "retry",                    TRUE},
  {"$V", "retry-connrefused",        FALSE},
  {"$h", "retry-delay",              TRUE},
  {"$h", "retry-delay",              TRUE},
  {"$i", "retry-max-time",           TRUE},
  {"$i", "retry-max-time",           TRUE},
  {"$k", "proxy-negotiate",          FALSE},
  {"$k", "proxy-negotiate",          FALSE},
@@ -793,6 +794,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
        if(err)
        if(err)
          return err;
          return err;
        break;
        break;
      case 'V': /* --retry-connrefused */
        config->retry_connrefused = toggle;
        break;
      case 'h': /* --retry-delay */
      case 'h': /* --retry-delay */
        err = str2unum(&config->retry_delay, nextarg);
        err = str2unum(&config->retry_delay, nextarg);
        if(err)
        if(err)
+2 −0
Original line number Original line Diff line number Diff line
@@ -198,6 +198,8 @@ static const char *const helptext[] = {
  "     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS",
  "     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS",
  "     --retry NUM   "
  "     --retry NUM   "
  "Retry request NUM times if transient problems occur",
  "Retry request NUM times if transient problems occur",
  "     --retry-connrefused  "
  "Consider \"connection refused\" a transient error",
  "     --retry-delay SECONDS  Wait SECONDS between retries",
  "     --retry-delay SECONDS  Wait SECONDS between retries",
  "     --retry-max-time SECONDS  Retry only within this period",
  "     --retry-max-time SECONDS  Retry only within this period",
  "     --sasl-ir       Enable initial response in SASL authentication",
  "     --sasl-ir       Enable initial response in SASL authentication",
+13 −1
Original line number Original line Diff line number Diff line
@@ -1441,6 +1441,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
            enum {
            enum {
              RETRY_NO,
              RETRY_NO,
              RETRY_TIMEOUT,
              RETRY_TIMEOUT,
              RETRY_CONNREFUSED,
              RETRY_HTTP,
              RETRY_HTTP,
              RETRY_FTP,
              RETRY_FTP,
              RETRY_LAST /* not used */
              RETRY_LAST /* not used */
@@ -1452,6 +1453,13 @@ static CURLcode operate_do(struct GlobalConfig *global,
               (CURLE_FTP_ACCEPT_TIMEOUT == result))
               (CURLE_FTP_ACCEPT_TIMEOUT == result))
              /* retry timeout always */
              /* retry timeout always */
              retry = RETRY_TIMEOUT;
              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) ||
            else if((CURLE_OK == result) ||
                    (config->failonerror &&
                    (config->failonerror &&
                     (CURLE_HTTP_RETURNED_ERROR == result))) {
                     (CURLE_HTTP_RETURNED_ERROR == result))) {
@@ -1499,7 +1507,11 @@ static CURLcode operate_do(struct GlobalConfig *global,


            if(retry) {
            if(retry) {
              static const char * const m[]={
              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 "
              warnf(config->global, "Transient problem: %s "