Zum Inhalt springen

Swallow Context Cancel (ARCH5168)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key go.logging.swallow-context-cancel · Severity warning · Category logging

Swallowing cancellation signals such as context.Canceled or context.DeadlineExceeded breaks shutdown and timeout propagation. These errors should be propagated to the caller, not hidden like an ordinary failure.

func run(ctx context.Context) error {
if err := work(ctx); err != nil {
if errors.Is(err, context.Canceled) {
return nil // cancellation swallowed
}
return err
}
return nil
}
func run(ctx context.Context) error {
if err := work(ctx); err != nil {
return fmt.Errorf("run: %w", err)
}
return nil
}

Propagate cancellation errors to the caller instead of swallowing them, so the shutdown flow works.