mkovac / notes

Go context timeouts I keep getting wrong

2026-05-14

Note to self: a timeout on the parent context also bounds every child. I spent an evening wondering why a 30s retry loop stopped after 5s.

ctx, cancel := context.WithTimeout(parent, 30*time.Second)
defer cancel()

If parent already has a 5s deadline, you get 5s. Check with ctx.Deadline() when in doubt.