{"record":{"id":"538571b40dcd8962","repo":"dotnet/yarp","slug":"the-timeout-was-not-applied-for-route-route-conf","errorCode":null,"errorMessage":"The timeout was not applied for route '{route.Config.RouteId}', ensure `IApplicationBuilder.UseRequestTimeouts()` is called between `IApplicationBuilder.UseRouting()` and `IApplicationBuilder.UseEndpoints()`.","messagePattern":"The timeout was not applied for route '(.+?)', ensure `IApplicationBuilder\\.UseRequestTimeouts\\(\\)` is called between `IApplicationBuilder\\.UseRouting\\(\\)` and `IApplicationBuilder\\.UseEndpoints\\(\\)`\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/ReverseProxy/Model/ProxyPipelineInitializerMiddleware.cs","lineNumber":108,"sourceCode":"            context.Features.Get<IHttpRequestTimeoutFeature>() is null &&\n            // The feature is skipped if the request is already canceled. We'll handle canceled requests later for consistency.\n            !context.RequestAborted.IsCancellationRequested &&\n            // The policy may set the timeout to null / infinite.\n            TimeoutPolicyRequestedATimeoutBeSet(requestTimeout))\n        {\n            // A timeout should have been set.\n            // Out of an abundance of caution, refuse the request rather than allowing it to proceed without the configured timeout.\n            ThrowIfDebuggerNotAttached(route);\n        }\n\n        void ThrowIfDebuggerNotAttached(RouteModel route)\n        {\n            // The feature is skipped if the debugger is attached.\n            if (!Debugger.IsAttached)\n            {\n                Log.TimeoutNotApplied(_logger, route.Config.RouteId);\n\n                throw new InvalidOperationException(\n                    $\"The timeout was not applied for route '{route.Config.RouteId}', \" +\n                    \"ensure `IApplicationBuilder.UseRequestTimeouts()` is called between \" +\n                    \"`IApplicationBuilder.UseRouting()` and `IApplicationBuilder.UseEndpoints()`.\");\n            }\n        }\n    }\n\n    private bool TimeoutPolicyRequestedATimeoutBeSet(RequestTimeoutAttribute requestTimeout)\n    {\n        if (requestTimeout.Timeout is not TimeSpan timeout)\n        {\n            if (requestTimeout.PolicyName is not string policyName)\n            {\n                Debug.Fail(\"Either Timeout or PolicyName should have been set.\");\n                return false;\n            }\n\n            if (!_timeoutOptions.CurrentValue.Policies.TryGetValue(policyName, out var policy))","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Model/ProxyPipelineInitializerMiddleware.cs#L90-L126","documentation":"When a route has a `RequestTimeoutAttribute` in its endpoint metadata but no `IHttpRequestTimeoutFeature` is present on the HttpContext, it means the ASP.NET Core request timeouts middleware (`UseRequestTimeouts`) did not run or was placed incorrectly. YARP detects this mismatch and throws rather than silently allowing a request to proceed without its configured timeout — a safety-first design choice. The check is skipped when a debugger is attached to allow debugging.","triggerScenarios":"A YARP route is configured with a timeout policy (`RequestTimeout` or a named timeout policy in the route config). The `RequestTimeoutAttribute` metadata is set on the endpoint. However, `IHttpRequestTimeoutFeature` is null because `app.UseRequestTimeouts()` was not called, or was called in the wrong position (not between `UseRouting()` and `UseEndpoints()`). The `EnsureRequestTimeoutPolicyIsAppliedCorrectly` method detects the missing feature and throws (unless a debugger is attached).","commonSituations":"A developer configures timeouts in the YARP config (`HttpRequest.ActivityTimeout` or timeout policies) but forgets to add `app.UseRequestTimeouts()` in Program.cs. The middleware is added but in the wrong order (after `UseEndpoints`, or before `UseRouting`). A framework upgrade changed where `UseRequestTimeouts` must be placed.","solutions":["Add `app.UseRequestTimeouts()` between `app.UseRouting()` and `app.UseEndpoints(...)` (or `app.MapReverseProxy()`) in Program.cs.","Verify the ordering: `UseRouting` → `UseRequestTimeouts` → `UseEndpoints`/`MapReverseProxy`. If any are swapped, the timeout feature won't be set.","If you don't want YARP to enforce request timeouts, remove the timeout configuration from the route/cluster config so no `RequestTimeoutAttribute` is attached.","During local debugging, note that the throw is suppressed when a debugger is attached — so this may only reproduce in deployed environments."],"exampleFix":"// before — UseRequestTimeouts missing\nvar app = builder.Build();\napp.UseRouting();\napp.MapReverseProxy(); // throws if route has timeout config\napp.Run();\n// after — correct middleware ordering\nvar app = builder.Build();\napp.UseRouting();\napp.UseRequestTimeouts();\napp.MapReverseProxy();\napp.Run();","handlingStrategy":"validation","validationCode":"// At startup, verify the middleware pipeline ordering\n// This is a code-structure assertion, not runtime:\n/*\nCorrect order:\n  app.UseRouting();\n  app.UseRequestTimeouts();\n  app.MapReverseProxy();\n*/\n// If timeouts are not configured on any route, UseRequestTimeouts is not needed.","typeGuard":"// No type guard — this is a middleware-ordering configuration issue.","tryCatchPattern":"// Not recommended — this is a fail-fast safety check by design.\n// Fix the middleware ordering instead of catching the exception.","preventionTips":["If any route has a timeout policy, always add app.UseRequestTimeouts() between UseRouting and MapReverseProxy.","Use the YARP Program.cs template as a reference for correct ordering.","Remember that the throw is suppressed when a debugger is attached — test in a non-debug build too."],"tags":["pipeline","timeout","middleware","configuration","ordering"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}