Per-attempt timeout or total deadline?
One request goes to a host that hangs and never answers. Both clients wait 2 seconds per attempt and allow 3 retries. Only the right one also sets a total deadline of 4 seconds.
Each row is one attempt. Press Play: the page slows down at key moments and says what happened.
Per-attempt timeout + total deadline
timeout: { attemptMs: 2000, totalMs: 4000 }When the caller hears back, by totalMs
The flat line ending in a square is the client with no deadline. The rising line is the client with a deadline, and its dot marks your current totalMs. Past the flat line, the deadline no longer helps.
Host time spent on hung attempts
Each attempt keeps the host busy while it waits. Aborting the attempt does not stop the host at once. In this model it works 6 more seconds.
What each timeout gives you
- attemptMs caps one attempt. A hung host costs at most
attemptMsper try, and the attempt ends with aTimeoutErrorthat Vereda retries. The timer also covers the body read and an asyncparse, whenparseorresponseTypeis set. - totalMs caps the whole request. The clock starts at
request()and counts everything: queue waits, rate-limit waits, attempts and backoff sleeps. At the deadline, Vereda aborts the attempt or wakes the sleep, and the ticket ends withDeadlineExceededError. - Doomed retries are skipped. If the next backoff would reach the deadline, the ticket fails now instead of sleeping first, with the last
TimeoutErrorascause. Set totalMs to 7 s: attempt #3 times out at 6.6 s, the 0.8 s backoff would reach 7 s, so the right lane stops right then.
What they cost
- A short
attemptMsalso cuts requests that were only slow. Each cut becomes a retry, and retries add load to a host that may already be struggling. - The deadline can cut an attempt that was about to answer. Vereda compares only the backoff delay with the deadline, not delay plus
attemptMs, so a retry that answers fast still fits. - Aborting is a client-side act. The host may keep working on the request. Vereda retries timeouts only for idempotent requests, so this is safe to repeat.
attemptMs: Infinityremoves the cap. Move the slider to the end and the left lane never answers. Onlycancel()ortotalMscan end the wait.
Things to try:
- Set totalMs to 1 s: the right lane aborts the first attempt.
- Set max retries to 0: the caller gets a plain
TimeoutErrorwith no wrapper. - Turn both timeouts off: neither lane ever answers.
In Vereda
This page follows the logic in three files:
src/queue/retry.ts: the deadline check before each backoff, and the abort path.src/queue/executor.ts: the attempt timer and the body read.src/core/client.ts: the deadline timer, armed insend().
The errors are in src/core/errors.ts. TimeoutError has kind: "timeout", DeadlineExceededError has kind: "deadline" and MaxRetriesExceededError has kind: "max_retries".
A test, test/demos/timeouts.parity.test.ts, checks this page's model against the real HttpClient: when each attempt starts and ends, when the caller hears back, and which error it gets. The page has to change when the library does.
The host's 6 s of extra work is invented for the chart, and no test checks it.
Model choices: backoff is 200 ms, 400 ms, 800 ms and so on, with jitter off so the numbers repeat. Vereda's default has full jitter, so each real wait is a random value up to that size.
Finite timeouts must fit in 231-1 ms. Infinity takes its own path in src/core/timer.ts, so it never fires early (#203).
A user cancel() ends the ticket at once with CancelledError and also aborts the attempt.
