Stage 3 · Build
Concurrency in Depth
Context Cancellation
Deadlines, cancellation trees, request-scoped values, and signal-aware shutdown.
Context Basics
Context carries deadlines, cancellation signals, and request-scoped values across goroutine boundaries. It is the standard way to control goroutine lifetimes in Go.
Cancellation Trees
Contexts form a tree. Canceling a parent cancels all its children. This is how request cancellation propagates through a call stack.
Deadlines and Timeouts
Deadlines and timeouts propagate through context chains. If a parent has a shorter deadline than a child, the parent's deadline wins.
Request-Scoped Values
context.WithValue carries request-scoped data: request IDs, authentication tokens, and tracing spans. Use typed keys to avoid collisions.
Signal Integration
Signal context converts OS signals into context cancellation. This is the standard pattern for graceful shutdown.
Anti-Patterns
Context carries deadlines, cancellation signals, and request-scoped values. It is not a general-purpose dependency injection container. Pass databases, loggers, and config as function parameters. Use context only for request-scoped data.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.