Skip to content

Fix race condition leak in RegisterResumptionStub#125407

Merged
jtschuster merged 2 commits intodotnet:mainfrom
jtschuster:SuppressReleaseInCreateResumptionStub
Mar 12, 2026
Merged

Fix race condition leak in RegisterResumptionStub#125407
jtschuster merged 2 commits intodotnet:mainfrom
jtschuster:SuppressReleaseInCreateResumptionStub

Conversation

@jtschuster
Copy link
Member

Move SuppressRelease() after SetMethodDescForEntryPointInNativeImage() and make it conditional on the insertion succeeding. Previously, if two threads raced past the initial check and both allocated a MethodDesc, the loser's allocation was leaked because SuppressRelease() was called unconditionally before the insert. Now the loser's AllocMemTracker will back out the allocation on destruction.

Changed SetMethodDescForEntryPointInNativeImage to return bool indicating whether the insertion occurred (true) or the entry already existed (false).

Move SuppressRelease() after SetMethodDescForEntryPointInNativeImage()
and make it conditional on the insertion succeeding. Previously, if two
threads raced past the initial check and both allocated a MethodDesc,
the loser's allocation was leaked because SuppressRelease() was called
unconditionally before the insert. Now the loser's AllocMemTracker will
back out the allocation on destruction.

Changed SetMethodDescForEntryPointInNativeImage to return bool indicating
whether the insertion occurred (true) or the entry already existed (false).

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

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 fixes a race-condition leak when registering ReadyToRun resumption stubs by only suppressing AllocMemTracker cleanup if the entry-point-to-MethodDesc mapping insertion actually succeeds.

Changes:

  • Change ReadyToRunInfo::SetMethodDescForEntryPointInNativeImage to return bool indicating whether it inserted a new mapping.
  • Update RegisterResumptionStub to call SuppressRelease() only when the mapping insertion succeeds, so the losing racer’s allocation is reclaimed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/vm/readytoruninfo.h Updates the helper API to return a bool result for “inserted vs already present”.
src/coreclr/vm/readytoruninfo.cpp Implements the bool return semantics and makes RegisterResumptionStub conditionally suppress AllocMemTracker cleanup based on insertion success.

@jtschuster jtschuster enabled auto-merge (squash) March 12, 2026 19:16
@jtschuster jtschuster merged commit 540910d into dotnet:main Mar 12, 2026
99 of 105 checks passed
@github-project-automation github-project-automation bot moved this to Done in AppModel Mar 12, 2026
Copilot AI pushed a commit that referenced this pull request Mar 13, 2026
Move SuppressRelease() after SetMethodDescForEntryPointInNativeImage()
and make it conditional on the insertion succeeding. Previously, if two
threads raced past the initial check and both allocated a MethodDesc,
the loser's allocation was leaked because SuppressRelease() was called
unconditionally before the insert. Now the loser's AllocMemTracker will
back out the allocation on destruction.

Changed SetMethodDescForEntryPointInNativeImage to return bool
indicating whether the insertion occurred (true) or the entry already
existed (false).

---------

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants