The client retries after network errors with growing pauses. If the overall budget is shorter than attempts plus pauses, everything ends with context deadline exceeded – and a good message also names the last cause.
Symptom
time GHREL_API=http://127.0.0.1:9 ./ghrel acme/tool time GHREL_API=http://127.0.0.1:9 ./ghrel -timeout 1s acme/tool ghrel: Get "http://127.0.0.1:9/repos/acme/tool/releases?per_page=5": dial tcp … … 3,591 total ghrel: context deadline exceeded (letzter Fehler: Get "http://127.0.0.1:9/repos… … 1,014 total
Without a budget it takes 3.6 s, with -timeout 1s it stops after 1 s. „letzter Fehler“ means “last error”.
Diagnosis
Compare the times: 3.6 s are one attempt plus three retries with 0.5 + 1 + 2 s backoff. With a 1 s budget the run ends while waiting.
ghrel: Get "http://127.0.0.1:9/repos/acme/tool/releases?per_page=5": dial tcp … … 3,591 total
Causes
deadline exceededOverall budget shorter than the retries
The context with timeout covers all attempts together. Once it expires, the next attempt or the wait stops immediately.
dial tcpReal cause: a network error
Port 9 is closed, every connection is refused at once – a network error, so it retries.
Fix
Don't: Just set a huge timeout. The tool then hangs for minutes during a real outage.
Go hands-on, Day 7: an HTTP client with retries, backoff and context, built into ghrel.
Go to day 7 →
FAQ
Why does the message contain the last error?
The client appends the cause of the last attempt. context deadline exceeded on its own would be useless for debugging.
How do I test this without the real GitHub?
With httptest.NewServer: a local server plays the API, including errors you could not trigger at GitHub on purpose.