Opt pooled async methods out of runtime async#67190
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ports the RuntimeAsyncMethodGenerationAttribute opt-out mechanism from dotnet/runtime to ASP.NET Core to prevent regressions when compiling pooled-async methods with “runtime async” enabled (until the pooled async method builder has a runtime-async replacement).
Changes:
- Add a shared internal
System.Runtime.CompilerServices.RuntimeAsyncMethodGenerationAttributepolyfill. - Apply
[RuntimeAsyncMethodGeneration(false)]to existing[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder...))]methods across Kestrel (HTTP/1.1, HTTP/2, HTTP/3), Quic transport, and sharedDuplexPipeStream. - Wire the shared attribute source into selected projects via
Compile Include=....
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj | Adds the shared runtime-async attribute source to Shared.Tests compilation. |
| src/Shared/ServerInfrastructure/DuplexPipeStream.cs | Opts the pooled-async ReadAsyncInternal implementation out of runtime async generation. |
| src/Shared/RuntimeAsync/RuntimeAsyncMethodGenerationAttribute.cs | Introduces the internal polyfill attribute type under System.Runtime.CompilerServices. |
| src/Servers/Kestrel/Transport.Quic/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj | Adds the shared runtime-async attribute source to the Quic transport project. |
| src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs | Opts multiple pooled async loops and DisposeAsync out of runtime async generation. |
| src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionContext.cs | Opts AcceptAsync (pooled async) out of runtime async generation. |
| src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj | Adds the shared runtime-async attribute source to Kestrel.Core compilation. |
| src/Servers/Kestrel/Core/src/Internal/Http3/Http3MessageBody.cs | Opts pooled async ReadAsync out of runtime async generation. |
| src/Servers/Kestrel/Core/src/Internal/Http2/Http2MessageBody.cs | Opts pooled async ReadAsync out of runtime async generation. |
| src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestStream.cs | Opts pooled async ReadAsyncInternal out of runtime async generation. |
| src/Servers/Kestrel/Core/src/Internal/Http/Http1UpgradeMessageBody.cs | Opts pooled async helper ReadAsyncInternalAwaited out of runtime async generation. |
| src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs | Opts pooled async ReadAsyncInternal out of runtime async generation. |
| src/Servers/IIS/IIS/src/Microsoft.AspNetCore.Server.IIS.csproj | Adds the shared runtime-async attribute source to the IIS server project. |
Comment on lines
116
to
118
| [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))] | ||
| [RuntimeAsyncMethodGeneration(false)] | ||
| private async ValueTask<int> ReadAsyncInternal(Memory<byte> destination, CancellationToken cancellationToken) |
javiercn
approved these changes
Jun 18, 2026
Port of dotnet/runtime#128943. Runtime async does not yet have a replacement for the pooled async method builder, so opt these methods out to avoid regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Several test projects and the http2cat sample glob ServerInfrastructure\**\*.cs and pull in DuplexPipeStream.cs without an explicit attribute reference, failing to compile. Move the polyfill into the same folder so it travels with the source. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b2e27c6 to
fdd8cd3
Compare
DeagleGross
approved these changes
Jun 18, 2026
This was referenced Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of dotnet/runtime#128943 to ASP.NET Core. Runtime async does not yet have a replacement for the pooled async method builder, so methods currently annotated with
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder...))]regress when compiled with runtime async. Opt them out for now.Approach
RuntimeAsyncMethodGenerationAttributepolyfill undersrc/Shared/RuntimeAsync/, matching the shape used by the runtime PR.PoolingAsyncValueTaskMethodBuildersite with[RuntimeAsyncMethodGeneration(false)]:DuplexPipeStream.ReadAsyncInternal(shared)Http1ContentLengthMessageBody,Http1UpgradeMessageBody,HttpRequestStream,Http2MessageBody,Http3MessageBodyQuicConnectionContext.AcceptAsyncand four methods onQuicStreamContextDuplexPipeStream.cs.Verified by building Kestrel.Core, Transport.Quic, and Shared.Tests locally.