تخطَّ إلى المحتوى

Swallow Context Cancel (ARCH5168)

هذا المحتوى غير متوفر بلغتك بعد.

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.