What problem does it solve?
This Skill helps developers correctly use context.Context across Go codebases to avoid goroutine leaks, orphaned work, incorrect cancellations, and deadline mismanagement that cause subtle production failures.
Core Features & Use Cases
- Parameter positioning and signatures: Ensure context is always the first parameter in functions and methods that accept it.
- Cancellation and timeouts: Guidance on deferring cancels, using WithTimeout/WithDeadline appropriately, and allocating timeout budgets for child operations.
- Context values and HTTP handling: Best practices for request-scoped values using unexported key types with accessors, and how to use r.Context() in HTTP handlers and middleware.
- Use Case: Audit an HTTP service to add context timeouts for database queries, ensure middleware attaches request IDs safely, and verify workers respect cancellation to prevent leaks.
Quick Start
Review the following Go code and correct context usage by ensuring context is the first parameter, adding deferred cancels where needed, applying appropriate timeouts and deadlines, and replacing any stored context fields.