We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RequestTimeouts not working, when I try out the request timeouts by following the document here https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0
it's not working as expected, no timeout while it should timeout
timeout
test code as below:
using Microsoft.AspNetCore.Http.Timeouts; var builder = WebApplication.CreateBuilder(args); builder.Services.AddRequestTimeouts(options => { options.DefaultPolicy = new RequestTimeoutPolicy() { Timeout = TimeSpan.FromSeconds(1), WriteTimeoutResponse = context => context.Response.WriteAsync("timeout") }; options.AddPolicy("timeout-2s", TimeSpan.FromSeconds(2)); }); var app = builder.Build(); app.UseRequestTimeouts(); app.Map("/", () => "Hello world"); app.MapGet("/timeout", async () => { await Task.Delay(TimeSpan.FromSeconds(5)); return Results.Content("No timeout!", "text/plain"); }); app.MapGet("/timeout-policy", async () => { await Task.Delay(TimeSpan.FromSeconds(5)); return Results.Content("No timeout!", "text/plain"); }).WithRequestTimeout("timeout-2s"); app.MapGet("/timeout-catch", [RequestTimeout(1000)]async () => { try { await Task.Delay(TimeSpan.FromSeconds(5)); } catch (TaskCanceledException) { return Results.Content("Timeout!", "text/plain"); } return Results.Content("No timeout!", "text/plain"); }); app.Run();
all these cases no timeout
No response
8.0.100-preview.7.23376.3
.NET SDK: Version: 8.0.100-preview.7.23376.3 Commit: daebeea8ea Runtime Environment: OS Name: Windows OS Version: 10.0.25947 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\ .NET workloads installed: There are no installed workloads to display. Host: Version: 8.0.0-preview.7.23375.6 Architecture: x64 Commit: 65b696cf5e RID: win-x64 .NET SDKs installed: 6.0.408 [C:\Program Files\dotnet\sdk] 7.0.102 [C:\Program Files\dotnet\sdk] 7.0.105 [C:\Program Files\dotnet\sdk] 8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-preview.7.23376.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
The text was updated successfully, but these errors were encountered:
Timeouts in asynchronous code or cooperative. Your code needs to use the RequestAborted cancellation token in order to get notified.
using Microsoft.AspNetCore.Http.Timeouts; var builder = WebApplication.CreateBuilder(args); builder.Services.AddRequestTimeouts(options => { options.DefaultPolicy = new RequestTimeoutPolicy() { Timeout = TimeSpan.FromSeconds(1), WriteTimeoutResponse = context => context.Response.WriteAsync("timeout") }; options.AddPolicy("timeout-2s", TimeSpan.FromSeconds(2)); }); var app = builder.Build(); app.UseRequestTimeouts(); app.Map("/", () => "Hello world"); app.MapGet("/timeout", async (CancellationToken token) => { await Task.Delay(TimeSpan.FromSeconds(5), token); return Results.Content("No timeout!", "text/plain"); }); app.MapGet("/timeout-policy", async () => { await Task.Delay(TimeSpan.FromSeconds(5)); return Results.Content("No timeout!", "text/plain"); }).WithRequestTimeout("timeout-2s"); app.MapGet("/timeout-catch", [RequestTimeout(1000)] async (CancellationToken token) => { try { await Task.Delay(TimeSpan.FromSeconds(5), token); } catch (TaskCanceledException) { return Results.Content("Timeout!", "text/plain"); } return Results.Content("No timeout!", "text/plain"); }); app.Run();
PS: You could that writes the response on timeout should check if the response has already started before doing so.
Sorry, something went wrong.
get it, thanks very much @davidfowl
No branches or pull requests
Is there an existing issue for this?
Describe the bug
RequestTimeouts not working, when I try out the request timeouts by following the document here
https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0
it's not working as expected, no timeout while it should timeout
Expected Behavior
timeout
Steps To Reproduce
test code as below:
all these cases no timeout
Exceptions (if any)
No response
.NET Version
8.0.100-preview.7.23376.3
Anything else?
The text was updated successfully, but these errors were encountered: