docs.jjon.com

Cancellation Propagation and Deadline Budgets in Go Services

Keeping tail latencies bounded across multi-hop RPC pipelines.

Key Rules

Always derive child contexts from the incoming request context and call defer cancel() immediately so timers are released before handler return.

ctx, cancel := context.WithTimeout(req.Context(), 3*time.Second)
defer cancel()