Skip to content

Handle DefaultConnectionContext abort/dispose cancellation race - #68146

Open
scarab-systems wants to merge 2 commits into
dotnet:mainfrom
scarab-systems:scarab-systems/aspnetcore-57098-abort-dispose
Open

Handle DefaultConnectionContext abort/dispose cancellation race#68146
scarab-systems wants to merge 2 commits into
dotnet:mainfrom
scarab-systems:scarab-systems/aspnetcore-57098-abort-dispose

Conversation

@scarab-systems

Copy link
Copy Markdown
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Handle DefaultConnectionContext abort/dispose cancellation race

Description

DefaultConnectionContext.Abort() queues cancellation of the connection-closed token on the ThreadPool. If the connection is disposed before that queued work runs, the queued Cancel() can observe a disposed CancellationTokenSource and raise ObjectDisposedException on the background worker.

This change makes the queued cancellation tolerate that already-disposed state. It also adds a RemoteExecutor regression test that forces the queued cancellation to run after DisposeAsync().

Validation:

  • ./restore.sh --no-build-nodejs --no-build-java --no-build-native
  • source ./activate.sh >/dev/null && dotnet test src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj --no-restore --filter DefaultConnectionContextDisposeAsyncAfterAbortDoesNotCrashProcess
  • source ./activate.sh >/dev/null && dotnet test src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj --no-restore

Fixes #57098

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 1, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @scarab-systems. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@scarab-systems

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@scarab-systems
scarab-systems marked this pull request as ready for review August 1, 2026 03:08
@gfoidl gfoidl added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 1, 2026
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

connection Abort + Dispose crashes process

2 participants