← Back to Docs

curl --retry in Cron Jobs: Which Errors It Retries

A cron job that calls an API with plain curl gets one try. Adding --retry helps, but it only retries some failures, and which ones surprises people. Everything below is from the curl man page.

What --retry retries

--retry 3 retries a transfer up to 3 times after a transient error, and curl defines that narrowly: a timeout, an FTP 4xx response, or an HTTP 408, 429, 500, 502, 503, 504, 522 or 524 response. Between tries it waits 1 second, then doubles the wait each time, up to 10 minutes. If the server sends a Retry-After header, curl uses it.

# retries a timeout or a 503, not a DNS failure or a refused connection
curl --retry 3 --max-time 30 -sS https://api.example.com/sync

What it does not retry

Widening it

--retry-connrefused adds refused connections to the transient list, which covers a server that is restarting. --retry-all-errors retries on any error. The man page calls it the sledgehammer and warns it can send duplicate data, so use it only for calls that are safe to repeat, such as a GET or an idempotent POST.

# a restarting server: refused connections count as transient
curl --retry 5 --retry-connrefused -sS https://api.example.com/sync

# any error, for a call that is safe to send twice
curl --retry 3 --retry-all-errors -sS https://api.example.com/health

Capping the time

--max-time limits one attempt. --retry-max-time limits the whole retry run, including the waits between tries, so a job that runs every 5 minutes does not overlap the next one. --retry-delay replaces the doubling wait with a fixed one.

# each try at most 20 s, all tries together at most 4 minutes
curl --retry 5 --max-time 20 --retry-max-time 240 -sS https://api.example.com/sync

When retries are not enough

curl retries inside one run of the job. If the endpoint is down for longer than your retry window, that run is lost, and cron does not record it anywhere unless you log it yourself. A hosted scheduler keeps the history: RunLater retries a failed call with exponential backoff, up to 10 times, and logs every attempt with its status and response so you can see what failed and when. See how RunLater retries.

Set this up in a few minutes

Paste the URL, pick a time or a cron schedule, and RunLater sends the request, retries it if it fails, and keeps the response.

Start a 14-day trialStarter is $15/month for 250 scheduled requests and 25,000 runs. Cancel before day 14 and you pay nothing.