I can't get the timeout to automatically trigger in the ASP.NET Core 8.0 Preview.
https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRequestTimeouts();
var app = builder.Build();
app.UseRequestTimeouts();
app.MapGet("/", async (HttpContext context) =>
{
try
{
await Task.Delay(TimeSpan.FromSeconds(10), context.RequestAborted);
}
catch (TaskCanceledException)
{
return Results.Content("Timeout!", "text/plain");
}
return Results.Content("No timeout.", "text/plain");
})
.WithRequestTimeout(TimeSpan.FromSeconds(1));
app.Run();
Expected output: Trigger a timeout after 1 second
Actual output: Returns success after 10 seconds
When you run your application with a debugger attached the request timeout check is skipped.
Microsoft.AspNetCore.Http.Timeouts.RequestTimeoutsMiddleware
that is added with UseRequestTimeouts
contains the following code:
internal sealed class RequestTimeoutsMiddleware
{
public Task Invoke(HttpContext context)
{
if (Debugger.IsAttached)
{
return _next(context);
}
...
}
}
https://github.com/dotnet/aspnetcore/blob/v8.0.0-preview.5.23302.2/src/Http/Http/src/Timeouts/RequestTimeoutsMiddleware.cs#L31
I believe using "Start Without Debugging" will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With