Reliability C# active any

Cancellation flows through async and long-running work

csharp-rel-001

Intent

Cancellation tokens are part of correctness in .NET request, I/O, and background code.

Applicability

Applies to async methods, request handlers, loops, and operations that may outlive the initiating caller.

What to inspect

Boundary signatures, downstream async calls, linked tokens, CPU loops, and cancellation exception handling.

Pass criteria

Relevant boundaries accept a CancellationToken, forward it downstream, and report honored cancellation correctly.

Fail criteria

The diff drops a visible token, substitutes CancellationToken.None, misuses Task.Run token semantics, or keeps long-running work running after cancellation.

Do not flag

Tiny synchronous helpers and externally constrained signatures that still honor available downstream cancellation.

Confidence guidance

HIGH when the dropped token or ignored cancellation is directly visible. MEDIUM when the full call chain is partly outside scope. LOW when cancellation relevance is unclear.

Remediation

Accept and propagate CancellationToken, link child timeouts to parent tokens, and stop loops promptly on cancellation.

Pass example

await _client.SendAsync(request, ct);

Fail example

await _client.SendAsync(request, CancellationToken.None);

Sources

  • ASP.NET Core Diagnostic Scenarios — David Fowler article
  • Cancellation blog series — Stephen Cleary article