Skip to content

HttpClient default and per request timeout: retarget net10.0, add timeout-vs-cancellation and resilience samples - #2234

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116682-aspnetcore-change-default-and-per-request-timeout-in-httpclient
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116682-aspnetcore-change-default-and-per-request-timeout-in-httpclient

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for "Change Default and per Request Timeout in HttpClient" (code-maze.com/aspnetcore-change-default-and-per-request-timeout-in-httpclient/). This PR touches only aspnetcore-features/HttpClientDefaultAndPerRequestTimeOut.

Changes:

  • Both projects retargeted from net8.0 to net10.0. The web project now has Nullable enabled (no new warnings).
  • Test packages: Microsoft.NET.Test.Sdk 17.8.0 to 18.10.1, xunit 2.5.3 to 2.9.3, xunit.runner.visualstudio 2.5.3 to 4.0.0, coverlet.collector 6.0.0 to 10.0.1, Microsoft.AspNetCore.Mvc.Testing 8.0.4 to 10.0.12.
  • Web project: Microsoft.Extensions.Http.Resilience 10.10.0 added. A second named client, ResilientClient, is registered with AddStandardResilienceHandler (2 second attempt timeout, 8 second total timeout), and /api/test-resilience-timeout reports the exception type and the client's Timeout after the call fails.
  • New /api/test-timeout-vs-cancellation endpoint that separates a timeout from a caller cancellation with catch (OperationCanceledException ex) when (ex.InnerException is TimeoutException).
  • Two new tests for the two endpoints, added to EndpointsLiveTests, so the CI filter FullyQualifiedName!~Live keeps skipping them like the existing four. They need port 5000 free and real wall-clock timeouts.
  • Removed template residue: the Microsoft.VisualStudio.Azure.Containers.Tools.Targets package with DockerDefaultTargetOS and DockerfileContext (the folder has no Dockerfile), AddControllers, MapControllers, UseAuthorization and UseHttpsRedirection (no controllers, no authorization, and the app listens on plain http://localhost:5000), and four using directives that ImplicitUsings already covers.
  • The three HttpResponseMessage locals are now declared with using var so they are disposed.

Package versions were re-queried on NuGet on 2026-09-23. Microsoft.NET.Test.Sdk is 18.10.1 today, one patch above the 18.10.0 the batch plan named, so 18.10.1 is what this PR uses. xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1, Microsoft.AspNetCore.Mvc.Testing 10.0.12 and Microsoft.Extensions.Http.Resilience 10.10.0 match the plan.

Verified locally on SDK 10.0.302, runtime Microsoft.NETCore.App 10.0.10: dotnet build -c Release with 0 warnings and 0 errors, dotnet test with 6 of 6 passing when the Live tests are run directly, dotnet test --filter "FullyQualifiedName!~Live" exits 0 with no test selected (what CI runs), and dotnet list package --vulnerable --include-transitive clean on both projects. launchSettings.json is unchanged.

…d resilience endpoints

- Both projects net8.0 to net10.0; web project Nullable enabled.
- Test packages: Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3,
  xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1,
  Microsoft.AspNetCore.Mvc.Testing 10.0.12.
- Add Microsoft.Extensions.Http.Resilience 10.10.0, a ResilientClient
  named client with AddStandardResilienceHandler, and
  /api/test-resilience-timeout.
- Add /api/test-timeout-vs-cancellation, which uses an exception filter
  on the nested TimeoutException.
- Two new tests in EndpointsLiveTests, so the CI Live filter still
  skips them.
- Drop the unused container tools package and its Docker properties,
  AddControllers, MapControllers, UseAuthorization, UseHttpsRedirection
  and four unused using directives.
- Dispose the three HttpResponseMessage locals with using var.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant