Curl retry mechanism

The following statement will retry 5 times or a maximum of 40 seconds with a connection timeout of 5 seconds, and no exponential backoff policy

curl --connect-timeout 5 \
    --max-time 10 \
    --retry 5 \
    --retry-delay 0 \
    --retry-max-time 40 \
    'http://your_url'


--max-time 10     (how long each retry will wait)
--retry 5         (it will retry 5 times)
--retry-delay 0   (an exponential backoff algorithm)
--retry-max-time  (total time before it's considered failed)

Note that there is also a --retry-connrefused (since curl 7.52.0) that retries even when the connection is refused and --retry-all-errors (since curl 7.71.0) which “is the sledgehammer of retrying”.

Leave a Comment