{"record":{"id":"06a447088fbcff1f","repo":"dotnet/reactive","slug":"the-operation-has-timed-out","errorCode":null,"errorMessage":"The operation has timed out.","messagePattern":"The operation has timed out\\.","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs","lineNumber":144,"sourceCode":"                            if (winner == delay)\n                            {\n                                // NB: We still have to wait for the MoveNextAsync operation to complete before we can\n                                //     dispose _enumerator. The resulting task will be used by DisposeAsync. Also note\n                                //     that throwing an exception here causes a call to DisposeAsync, where we pick up\n                                //     the task prepared below.\n\n                                // NB: Any exception reported by a timed out MoveNextAsync operation won't be reported\n                                //     to the caller, but the task's exception is not marked as observed, so unhandled\n                                //     exception handlers can still observe the exception.\n\n                                // REVIEW: Should exceptions reported by a timed out MoveNextAsync operation come out\n                                //         when attempting to call DisposeAsync?\n\n                                _loserTask = next.ContinueWith((_, state) => ((IAsyncDisposable)state!).DisposeAsync().AsTask(), _enumerator);\n\n                                _sourceCTS!.Cancel();\n\n                                throw new TimeoutException();\n                            }\n\n                            delayCts.Cancel();\n                        }\n\n                        if (await moveNext.ConfigureAwait(false))\n                        {\n                            _current = _enumerator.Current;\n                            return true;\n                        }\n\n                        break;\n                }\n\n                await DisposeAsync().ConfigureAwait(false);\n                return false;\n            }\n        }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs#L126-L162","documentation":"AsyncEnumerable.Timeout throws TimeoutException when the source does not produce its next element within the configured time window. Upon timeout the operator cancels the source (via its CancellationTokenSource) and schedules the enumerator's DisposeAsync before raising the exception.","triggerScenarios":"Enumerating AsyncEnumerable.Timeout(source, timeout, ...) (or WithTimeout) where a MoveNextAsync on the source exceeds the allowed duration; also when the delay task wins the race against the source's next element.","commonSituations":"Downstream services slow or hung (network latency, dead database connection); timeout value set too low for expected processing time; token/CTS misconfiguration causing source to ignore cancellation until after the deadline.","solutions":["Increase the timeout duration to a realistic bound for the slowest expected source emission.","Fix the underlying source's latency (connection pooling, query tuning, retry with backoff).","Catch TimeoutException and apply a fallback/restart strategy, e.g. .Catch((TimeoutException) => fallbackSequence).","Ensure the source honors the CancellationToken passed so cancellation propagates promptly."],"exampleFix":"// before\nawait foreach (var x in src.Timeout(TimeSpan.FromSeconds(1))) Consume(x);\n// after\nawait foreach (var x in src\n    .Timeout(TimeSpan.FromSeconds(30))\n    .Catch<int, TimeoutException>(_ => AsyncEnumerable.Return(-1)))\n    Consume(x);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await foreach (var x in src.Timeout(d)) ... }\ncatch (TimeoutException) { fallback(); }","preventionTips":["Size the timeout above worst-case source latency.","Ensure the source honors cancellation tokens.","Add .Catch<int, TimeoutException> fallbacks for resilience.","Monitor upstream latency so timeouts aren't the first signal."],"tags":["timeout","async-streams","cancellation","latency"],"backgroundTag":"request-timeout","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}