Path: redb-route/redb.Route/Core/RouteCancellation.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Core/RouteCancellation.cs ---- namespace redb.Route.Core; /// /// The one rule that tells a cancellation from a failure, and the one place an owned timeout is named as /// one. Shared by error handling and by every component that runs under a deadline. /// /// A cancellation is what the caller's asked for. An /// raised while that token is still live is NOT a cancellation: it /// is a timeout (an HttpClient deadline, a component's own guard) or an internal abort, and error handling /// must see it like any other failure. Keying the pass-through on the exception type alone was the bug: an /// HTTP producer's timeout is a , so TryCatch/Catch, OnException, Retry /// and DeadLetterChannel all treated it as cancellation and skipped it, and the exchange died whole. /// /// /// Error handling normalizes such an exception to (the original kept as /// ) so a route can name it — Catch<TimeoutException>, /// OnException<TimeoutException>, <catch exceptions="System.TimeoutException"> — /// instead of the symptom type . A genuine cancellation is never /// normalized and never handled. /// /// public static class RouteCancellation { /// /// True when the exception is the cancellation asked for. Everything else — /// including an raised while is still /// live — is a failure error handling must see. /// public static bool IsCancellation(Exception ex, CancellationToken ct) => ex is OperationCanceledException && ct.IsCancellationRequested; /// /// True when the exception is an that is NOT the caller's /// cancellation: a timeout or an internal abort that error handling must treat as a failure. /// public static bool IsOwnedTimeout(Exception ex, CancellationToken ct) => ex is OperationCanceledException && !ct.IsCancellationRequested; /// /// True when is or a subtype /// (). Error handling never handles such a type — a genuine /// cancellation is filtered out and a timeout arrives as — so a /// Catch<T> / OnException<T> on one is a branch that can never fire. /// public static bool IsCancellationType(Type exceptionType) => typeof(OperationCanceledException).IsAssignableFrom(exceptionType); /// /// Names an owned timeout as one for error handling: an raised /// while is still live becomes a carrying the /// original as . Anything else, a genuine cancellation included, is /// returned unchanged. The result is what to act on — assign to , match /// handlers against, or rethrow. /// /// The caught exception. /// The token the operation ran under — the caller's. /// Message for the produced ; a generic one by default. public static Exception Normalize(Exception ex, CancellationToken ct, string? message = null) => IsOwnedTimeout(ex, ct) ? new TimeoutException( message ?? "The operation timed out: it was cancelled by a deadline, not by the caller's token.", ex) : ex; }