Skip to content
context.Context
step 1/5

Reading — step 1 of 5

Learn

~1 min readConcurrency at Scale

context.Context is how Go propagates cancellation, deadlines, and request-scoped values through call chains.

Every Go function that does I/O or blocks should accept a ctx context.Context as its FIRST argument.

go

Creating contexts:

go

Patterns:

go

context.WithValue is for request-scoped data only — request ID, trace span, auth user. Don't use it as a function-arg replacement.

The cardinal rule: if a goroutine outlives its caller, it should accept a context and check ctx.Done(). Goroutine leaks are the #1 Go bug at scale.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…

context.Context — Go Advanced