Skip to content

Conversation

@elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Oct 6, 2025

  • Defer DomainAssembly/Assembly/Module creation until after FileLoadLock creation
  • Add a FILE_LOAD_ALLOCATE stage to the FileLoadLevel enum, representing the point at which DomainAssembly and Assembly objects are allocated and associated with the lock.
  • Create FileLoadLock without an associated Assembly initially. The Assembly is now set later, at the allocation stage, via the new SetAssembly method.
  • Update the moduleload profile test project to trigger concurrent module loads. It won't always hit the issue being fixed here, but should decently often (9/10 times when I ran locally).

See #120296

Copilot AI review requested due to automatic review settings October 6, 2025 22:27
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 in the CoreCLR runtime that occurs during concurrent DomainAssembly/Assembly/Module creation, which could result in incorrectly triggered ICorProfiler callbacks. The fix introduces proper sequencing by deferring assembly object creation until after FileLoadLock creation.

  • Adds a new FILE_LOAD_ALLOCATE stage to the FileLoadLevel enum to represent when DomainAssembly and Assembly objects are allocated
  • Modifies FileLoadLock creation to initially have no associated Assembly, with the Assembly set later via a new SetAssembly method
  • Updates the test project to trigger concurrent module loads that can reproduce the race condition

Reviewed Changes

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

Show a summary per file
File Description
src/tests/profiler/unittest/moduleload.csproj Adds reference to unloadlibrary project for concurrent testing
src/tests/profiler/unittest/moduleload.cs Adds multi-threaded assembly loading test to trigger race conditions
src/coreclr/vm/assemblyspec.hpp Adds FILE_LOAD_ALLOCATE enum value and updates comments
src/coreclr/vm/appdomain.hpp Updates FileLoadLock interface to support deferred Assembly association
src/coreclr/vm/appdomain.cpp Implements deferred Assembly creation and new allocation stage logic

@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

elinor-fung and others added 2 commits October 7, 2025 10:58
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
@elinor-fung elinor-fung merged commit eb19df0 into dotnet:main Oct 7, 2025
104 checks passed
@elinor-fung elinor-fung deleted the assembly-create-race branch October 7, 2025 23:00
@elinor-fung
Copy link
Member Author

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18328456863

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants