Skip to content

Opt pooled async methods out of runtime async#67190

Merged
BrennanConroy merged 2 commits into
mainfrom
brennanconroy/port-runtime-opt-out
Jun 20, 2026
Merged

Opt pooled async methods out of runtime async#67190
BrennanConroy merged 2 commits into
mainfrom
brennanconroy/port-runtime-opt-out

Conversation

@BrennanConroy

Copy link
Copy Markdown
Member

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

  • Added an internal RuntimeAsyncMethodGenerationAttribute polyfill under src/Shared/RuntimeAsync/, matching the shape used by the runtime PR.
  • Annotated every existing PoolingAsyncValueTaskMethodBuilder site with [RuntimeAsyncMethodGeneration(false)]:
    • DuplexPipeStream.ReadAsyncInternal (shared)
    • Kestrel.Core: Http1ContentLengthMessageBody, Http1UpgradeMessageBody, HttpRequestStream, Http2MessageBody, Http3MessageBody
    • Transport.Quic: QuicConnectionContext.AcceptAsync and four methods on QuicStreamContext
  • Wired the shared attribute file into the three projects that need it (Kestrel.Core, Transport.Quic, IIS) plus Shared.Tests, since IIS and Shared.Tests both share-in DuplexPipeStream.cs.

Verified by building Kestrel.Core, Transport.Quic, and Shared.Tests locally.

Copilot AI review requested due to automatic review settings June 12, 2026 20:11
@BrennanConroy BrennanConroy requested a review from halter73 as a code owner June 12, 2026 20:11

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.

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.RuntimeAsyncMethodGenerationAttribute polyfill.
  • Apply [RuntimeAsyncMethodGeneration(false)] to existing [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder...))] methods across Kestrel (HTTP/1.1, HTTP/2, HTTP/3), Quic transport, and shared DuplexPipeStream.
  • 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)
BrennanConroy and others added 2 commits June 18, 2026 09:41
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>
@javiercn javiercn force-pushed the brennanconroy/port-runtime-opt-out branch from b2e27c6 to fdd8cd3 Compare June 18, 2026 07:41
@BrennanConroy BrennanConroy merged commit fb525db into main Jun 20, 2026
23 of 25 checks passed
@BrennanConroy BrennanConroy deleted the brennanconroy/port-runtime-opt-out branch June 20, 2026 04:43
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.

4 participants