Awesome Reviewers

When adding or modifying concurrent code, treat context/cancellation, goroutine lifecycle, and state ownership as first-class requirements.

Practical standards: 1) Always pass the caller’s ctx down the call chain

2) Never block forever on goroutine completion

3) Don’t share mutable variables between goroutines

4) Make teardown cancellation effective

5) Ensure async goroutines don’t outlive tests/owner scopes

6) State handovers must have clear ownership and ordering

7) Test isolation under concurrency

Illustrative patterns:

A) Cancel-aware goroutine completion without shared err

errCh := make(chan error, 1)
go func() {
    // compute / call that may block
    errCh <- runtimeService.StopContainer(ctx, id, grace)
}()
select {
case <-ctx.Done():
    // caller cancelled; return quickly
    return ctx.Err()
case err := <-errCh:
    return err
}

B) Goroutine leak prevention in tests

done := make(chan struct{})
go func() {
    defer close(done)
    _ = obj.Run(ctx, sourcesReady)
}()
// ... trigger stop
cancel()          // or close(stopCh)
<-done            // wait until Run actually exits

C) Don’t hide non-cancellable waits