proper context handling

Always propagate contexts consistently throughout the call chain and handle context cancellation properly in concurrent operations. When a context is available in the current scope, reuse it instead of creating a new background context. For operations that may block (like time.Sleep), use context-aware alternatives to prevent goroutine leaks when requests...

copy reviewer prompt

Prompt

Reviewer Prompt

Always propagate contexts consistently throughout the call chain and handle context cancellation properly in concurrent operations. When a context is available in the current scope, reuse it instead of creating a new background context. For operations that may block (like time.Sleep), use context-aware alternatives to prevent goroutine leaks when requests are cancelled.

Example of proper context cancellation handling:

// Instead of:
time.Sleep(res.Delay)

// Use:
select {
case <-ctx.Done():
    return Result{Ok: false}, nil
case <-time.After(res.Delay):
}

This ensures that goroutines don’t remain active after their associated request context has been cancelled, preventing resource leaks and improving application responsiveness.

Source discussions