Skip to content

fix PinnedBlockMemoryPoolFactory DI dependency on TimeProvider - #69709

Merged
DeagleGross merged 1 commit into
dotnet:mainfrom
DeagleGross:deaglegross-automatic-robot
Oct 8, 2026
Merged

DeagleGross merged 1 commit into
dotnet:mainfrom
DeagleGross:deaglegross-automatic-robot

Conversation

@DeagleGross

Copy link
Copy Markdown
Member

Made PinnedBlockMemoryPoolFactory use TimeProvider.System as a default TimeProvider. Tests could still override the instance using internal constructor. That solves the Singleton<->Scoped resolution problems in the case TimeProvider is a scoped service:

var builder = WebApplication.CreateBuilder(args);
services.AddScoped<TimeProvider, CustomTimeProvider>();
var app = builder.Build();
await app.RunAsync();

internal class CustomTimeProvider : TimeProvider { }

Fixes #67957

@DeagleGross DeagleGross self-assigned this Oct 7, 2026
Copilot AI balanced review requested due to automatic review settings October 7, 2026 21:44
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Oct 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unrelated expression-body refactor should be reverted to preserve a minimal diff.

1 open finding
What changed in this PR

Decouples Kestrel’s singleton memory-pool factory from application-registered TimeProvider services.

Changes:

  • Uses TimeProvider.System for DI construction.
  • Retains internal time-provider injection for tests.
  • Adds scoped-service regression coverage.
File Description
PinnedBlockMemoryPoolFactory.cs Separates DI and test constructors.
PinnedBlockMemoryPoolFactoryTests.cs Updates test construction helper.
WebHostBuilderKestrelExtensionsTests.cs Verifies scoped TimeProvider compatibility.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@DeagleGross

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@DeagleGross

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validating the service descriptor for PinnedBlockMemoryPoolFactory fails when a custom scoped TimeProvider is registered

3 participants