research/a-503-maintenance-page-with-retry-after

A Maintenance Page That Answers 503 With Retry-After: What curl, fetch and a Retry Helper Do With It

Engineering Note · November 27, 2026 · 9 minute read · HTTP · Node.js · curl · Testing

A maintenance page should answer with status 503 Service Unavailable and a Retry-After header, so every client knows the outage is temporary and when to come back. We served one from a local Node.js server and pointed three clients at it. curl 8.5.0 honored Retry-After in both its forms when given --retry, but without -f it exited 0 and printed the maintenance page as if it were the real content. Node.js fetch returned the 503 without retrying or throwing. And the retry helper from our earlier note retried with no wait at all when the header was negative, because its parser was too loose.

Everything below was run on Linux with Node.js 22.23.5 and curl 8.5.0, against a server on localhost. The outputs are real.

Why 503 and not a friendly 200?

A maintenance page that answers 200 OK tells every script, uptime check and search crawler that “Back soon” is the page’s real content. A 503 says the service is temporarily unavailable. Retry-After says for how long, either as a number of seconds or as a date. Scripts can wait and retry, and monitoring can tell “down for maintenance” apart from “up”.

We also send Cache-Control: no-store, so a cache between the server and the visitor does not hold on to the maintenance page after the site is back.

What did the test server do?

One small server that answers 503 with a chosen Retry-After for the first k requests to a URL, then 200:

import http from 'node:http';
// /secs/<n>/<k>: 503 with "Retry-After: <n>" for the first k requests, then 200
// /date/<n>/<k>: same, but Retry-After as an HTTP-date n seconds ahead
// /raw/<value>/<k>: Retry-After sent exactly as given
const hits = {};
const t0 = Date.now();
http.createServer((req, res) => {
  const [, kind, val, k] = req.url.split('/');
  const n = (hits[req.url] = (hits[req.url] ?? 0) + 1);
  console.log(`${((Date.now() - t0) / 1000).toFixed(1)}s ${req.method} ${req.url} #${n}`);
  if (n > Number(k)) { res.writeHead(200, { 'Content-Type': 'text/plain' }); return res.end('open again\n'); }
  const retryAfter = kind === 'secs' ? val
    : kind === 'date' ? new Date(Date.now() + Number(val) * 1000).toUTCString()
    : decodeURIComponent(val);
  res.writeHead(503, { 'Content-Type': 'text/html', 'Retry-After': retryAfter, 'Cache-Control': 'no-store' });
  res.end('<h1>Back soon</h1><p>We are updating the site.</p>\n');
}).listen(3200, () => console.log('maintenance server on 3200'));

Each URL ends in a unique letter so every test starts with a fresh hit count. The exit code and elapsed time come from a small shell wrapper.

What does curl do with a 503 by default?

$ curl -s http://localhost:3200/secs/2/1/a
<h1>Back soon</h1><p>We are updating the site.</p>
exit 0 after 0.0s

$ curl -s -o /dev/null -w %{http_code}\n http://localhost:3200/secs/2/1/b
503
exit 0 after 0.0s

$ curl -sf http://localhost:3200/secs/2/1/c
exit 22 after 0.0s

Plain curl printed the maintenance page and exited 0. A backup script, a deploy check or a cron job that downloads a file would carry on as if it had worked, and might save “Back soon” over the real data. With -f (--fail), curl printed nothing and exited 22, which a script can catch.

Does curl —retry honor Retry-After?

Yes. The curl 8.5.0 documentation for --retry lists 503 as a transient error and says “curl complies with the Retry-After: response header if one was present to know when to issue the next retry (added in 7.66.0).” The server’s log shows when each request arrived:

$ curl -s --retry 3 http://localhost:3200/secs/2/2/d
<h1>Back soon</h1><p>We are updating the site.</p>
<h1>Back soon</h1><p>We are updating the site.</p>
open again
exit 0 after 4.0s

$ curl -s --retry 3 http://localhost:3200/date/3/1/e
<h1>Back soon</h1><p>We are updating the site.</p>
open again
exit 0 after 3.0s

$ curl -s --retry 3 --retry-delay 1 http://localhost:3200/secs/4/1/g
<h1>Back soon</h1><p>We are updating the site.</p>
open again
exit 0 after 4.0s
0.5s GET /secs/2/2/d #1
2.5s GET /secs/2/2/d #2
4.5s GET /secs/2/2/d #3
4.5s GET /date/3/1/e #1
7.5s GET /date/3/1/e #2
7.6s GET /secs/4/1/g #1
11.6s GET /secs/4/1/g #2

Retry-After: 2 meant 2-second gaps. An HTTP-date 3 seconds ahead meant a 3-second wait. Retry-After: 4 overrode --retry-delay 1.

Look at the output, though. Without -f, every 503 body went to standard output, so the result was two copies of the maintenance page followed by the real content. With -f, or with -o to a file, only the final good response was kept:

$ curl -sf --retry 3 http://localhost:3200/secs/2/1/i
open again
exit 0 after 2.0s

$ curl -s --retry 3 -o out2.html http://localhost:3200/secs/2/2/l2
exit 0 after 4.0s
$ cat out2.html
open again

When the retries ran out, the exit code again depended on -f. Five 503s in a row with --retry 2 gave exit 0 and three maintenance pages without -f, and exit 22 with it.

Can the server make curl wait too long?

Yes. --max-time limits each transfer, not the wait between them. With Retry-After: 30, curl slept the full 30 seconds even with --max-time 2:

$ curl -sS --retry 1 --max-time 2 http://localhost:3200/secs/30/1/o
<h1>Back soon</h1><p>We are updating the site.</p>
open again
exit 0 after 30.0s

--retry-max-time is the limit on the whole retry period. With a 10-second limit and Retry-After: 60, curl gave up after the first answer instead of sleeping a minute:

$ curl -sf --retry 3 --retry-max-time 10 http://localhost:3200/secs/60/1/k
exit 22 after 0.0s

Values curl cannot use are not fatal. Retry-After: soon and Retry-After: 0 both led to a retry after 1 second, curl’s normal first backoff.

For scripts, the safe set is curl -fsS --retry 3 --retry-max-time 60 -o file URL: fail on HTTP errors, show errors, retry transient failures, never wait longer than a minute in total, and keep only a good response.

What does fetch do with a 503?

Nothing special. It returns the response:

const t = Date.now();
const res = await fetch('http://localhost:3200/secs/2/1/p');
console.log({ status: res.status, ok: res.ok, retryAfter: res.headers.get('retry-after'), ms: Date.now() - t });
console.log('body:', (await res.text()).trim());
try { await fetch('http://localhost:3200/secs/2/1/q').then((r) => r.json()); }
catch (e) { console.log('r.json() on the maintenance page:', e.name, '-', e.message); }
{ status: 503, ok: false, retryAfter: '2', ms: 44 }
body: <h1>Back soon</h1><p>We are updating the site.</p>
r.json() on the maintenance page: SyntaxError - Unexpected token '<', "<h1>Back s"... is not valid JSON

fetch does not throw for an HTTP error status. A 503 is a successful fetch of an error page. Code that skips the res.ok check gets a confusing JSON error from deep inside the parse, nowhere near the cause.

How did our earlier retry helper handle it?

In Retrying a Flaky HTTP Call With Backoff and a Deadline we wrote a fetchWithRetry helper that reads Retry-After. We ran that code, unchanged from the post, against the maintenance server:

  try 1: HTTP 503; waiting 2000 ms
/secs/2/1/r: 200 after 2043 ms
  try 1: HTTP 503; waiting 60000 ms would pass the deadline, giving up
/secs/60/1/s: threw "HTTP 503" after 2 ms
  try 1: HTTP 503; waiting -5000 ms
  try 2: HTTP 503; waiting -5000 ms
/raw/-5/2/t: 200 after 9 ms

The first two cases are right: it waited the 2 seconds asked for, and gave up at once on a 60-second wait that would pass its 4-second deadline. The third is a bug. Retry-After: -5 produced a negative wait, setTimeout treated it as no wait, and the helper hit the server again immediately. A misconfigured proxy that sent that header could get hammered by every client using it.

The cause is the parser, which uses Number(). We fed it a range of header values and compared it with a stricter version:

// the parser from our Nov 23 note
function loose(h) {
  if (!h) return null;
  const secs = Number(h);
  if (Number.isFinite(secs)) return secs * 1000;
  const when = Date.parse(h);
  return Number.isNaN(when) ? null : Math.max(0, when - Date.now());
}
// stricter: whole seconds or an HTTP-date, never negative, capped
function strict(h, capMs = 10 * 60_000) {
  if (h == null) return null;
  h = h.trim();
  let ms = null;
  if (/^\d+$/.test(h)) ms = Number(h) * 1000;
  else if (/^[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(h)) {
    const when = Date.parse(h);
    if (!Number.isNaN(when)) ms = Math.max(0, when - Date.now());
  }
  return ms == null ? null : Math.min(ms, capMs);
}
value                            loose (ms)     strict (ms)
"120"                            120000         120000
"Thu, 26 Nov 2026 20:07:23 GMT"  4600           4600
"0"                              0              0
" 3 "                            3000           3000
"2.5"                            2500           null
"-5"                             -5000          null
"1e3"                            1000000        null
"0x10"                           16000          null
"soon"                           null           null
""                               null           null
"2026"                           2026000        600000
"Fri, 27 Nov 2026"               13961600       null
"86400"                          86400000       600000

Number() accepts negative numbers, decimals, exponents and hex, so 1e3 became a 16-minute wait and -5 became none. Date.parse accepts partial dates, so Fri, 27 Nov 2026 became a wait of almost four hours until midnight UTC. The strict version takes whole seconds or the full date format a server sends, returns null for anything else (so the helper falls back to its own jittered backoff), and caps everything at 10 minutes. The date row shows 4,600 ms rather than 5,000 because the HTTP-date format has no fractions of a second.

If you copied the helper from that note, replace retryAfterMs with a parser like strict, or at least wrap its result in Math.max(0, …).

A checklist for a maintenance page

  • Answer 503, never 200, for every URL while you are down, including API routes.
  • Send Retry-After with a realistic number of seconds. Too short and clients keep knocking; too long and they give up.
  • Send Cache-Control: no-store on the maintenance response.
  • In shell scripts, use curl -fsS --retry 3 --retry-max-time 60 and write to a file with -o.
  • In code, check res.ok after fetch, and parse Retry-After strictly: whole seconds or an HTTP-date, never negative, capped.

Limitations

  • We tested one curl version (8.5.0). The current curl documentation adds 522 and 524 to the list of transient errors and allows decimal values for --retry-max-time from curl 8.16.0, so newer versions behave somewhat differently.
  • We did not test browsers, search engine crawlers, CDNs or uptime services. How they treat a 503 and Retry-After is up to each one, and we could not test them here.
  • fetch was Node.js 22’s built-in version. We did not test fetch in browsers, Deno or Bun, or libraries such as axios.
  • The strict parser accepts only dates laid out like Thu, 26 Nov 2026 20:07:23 GMT, the form toUTCString() produces and our server sent. Any other date layout is rejected and falls back to the helper’s own backoff. We did not test servers that send other layouts.
  • All requests went to localhost, so timings show only the waits, not network time.

Sources

Frequently asked questions

What status code should a maintenance page return?

503 Service Unavailable, with a Retry-After header giving the number of seconds until you expect to be back, or a date. A 200 tells every client and script that the maintenance page is the real content. Add Cache-Control: no-store so a cache in front of the site does not keep serving the page after you are back.

Does curl respect the Retry-After header?

Yes, when you pass --retry. In our test with curl 8.5.0, a 503 with Retry-After: 2 made curl wait 2 seconds, and an HTTP-date 3 seconds ahead made it wait 3. Retry-After also overrode --retry-delay. Without --retry, curl does not retry at all.

Why does curl exit 0 on a 503?

Because an HTTP error response is still a completed transfer. Without -f (--fail), curl prints the error page and exits 0, so a script carries on as if it worked. With -f, curl printed nothing for the 503 and exited 22 in our test. Use -f in every script that checks a site or downloads something.

Does fetch retry on 503 in Node.js?

No. In Node.js 22, fetch returned the 503 response at once with res.ok set to false and the Retry-After header readable. It does not throw, so code that only catches errors will read the maintenance page as data. Check res.ok, and retry yourself if the call should survive maintenance.

How should code parse Retry-After?

Accept whole seconds or an HTTP-date, and nothing else. Never let it go negative, and cap it at the longest you are willing to wait. A plain Number() parse accepts values such as -5, 2.5, 1e3 and 0x10; in our test, -5 made our earlier helper retry twice in 9 ms with no wait.

More from Research

← All research