]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: stop retry if Retry-After: is longer than allowed
authorDaniel Stenberg <daniel@haxx.se>
Mon, 6 Sep 2021 07:08:01 +0000 (09:08 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 6 Sep 2021 12:46:45 +0000 (14:46 +0200)
If Retry-After: specifies a period that is longer than what fits within
--retry-max-time, then stop retrying immediately.

Added test 366 to verify.

Reported-by: Kari Pahula
Fixes #7675
Closes #7676

src/tool_operate.c
tests/data/Makefile.inc
tests/data/test366 [new file with mode: 0644]

index 960f3020a037d4e2f52a6757e71bc4cb5479e636..ca53d29f7d42975b578523a5baff946640840570 100644 (file)
@@ -515,6 +515,21 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
             sleeptime = LONG_MAX;
           else
             sleeptime = (long)retry_after * 1000; /* milliseconds */
+
+          /* if adding retry_after seconds to the process would exceed the
+             maximum time allowed for retrying, then exit the retries right
+             away */
+          if(config->retry_maxtime) {
+            curl_off_t seconds = tvdiff(tvnow(), per->retrystart)/1000;
+
+            if((CURL_OFF_T_MAX - retry_after < seconds) ||
+               (seconds + retry_after > config->retry_maxtime)) {
+              warnf(config->global, "The Retry-After: time would "
+                    "make this command line exceed the maximum allowed time "
+                    "for retries.");
+              goto noretry;
+            }
+          }
         }
       }
       warnf(config->global, "Problem %s. "
@@ -570,6 +585,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
       return CURLE_OK;
     }
   } /* if retry_numretries */
+  noretry:
 
   if((global->progressmode == CURL_PROGRESS_BAR) &&
      per->progressbar.calls)
index 4fd9b6fe02a2aecd595a49f9fb6d9fca6576ef76..6c6ab09de6bb683a90809456120a543d637f1e60 100644 (file)
@@ -60,7 +60,7 @@ test325 test326 test327 test328 test329 test330 test331 test332 test333 \
 test334 test335 test336 test337 test338 test339 test340 test341 test342 \
 test343 test344 test345 test346 test347 test348 test349 test350 test351 \
 test352 test353 test354 test355 test356 test357 test358 test359 test360 \
-test361 test362 test363 test364 test365 \
+test361 test362 test363 test364 test365 test366 \
 \
 test392 test393 test394 test395 test396 test397 \
 \
diff --git a/tests/data/test366 b/tests/data/test366
new file mode 100644 (file)
index 0000000..748ef4a
--- /dev/null
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+retry
+</keywords>
+</info>
+#
+# Server-side
+<reply>
+<data>
+HTTP/1.1 503 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Content-Length: 21
+Retry-After: 200
+
+server not available
+</data>
+
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP --retry-max-time with too long Retry-After
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER --retry 2 --retry-max-time 10
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+
+</verify>
+</testcase>