Repository navigation
Remove another race condition in LazyLoader - #39464
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Manual validation is needed because the synchronization and AsyncLocal reentrancy changes affect recursive and cross-thread Load/LoadAsync interleavings that the current stress test does not cover.
No open issues 🎉
What changed in this PR
This pull request removes a race condition in LazyLoader navigation load-state tracking and adds concurrent regression coverage.
Changes:
- Replaces the non-thread-safe loaded-state dictionary with
ConcurrentDictionary. - Moves loading-depth updates outside the loading-state lock in synchronous and asynchronous paths.
- Adds multithreaded tests for initialized and uninitialized navigation states.
- The test barriers should be made failure-safe to prevent hangs when a worker fails before reaching the second barrier.
This pull request requires changes.
| File | Description |
|---|---|
test/EFCore.Tests/Infrastructure/Internal/LazyLoaderTest.cs |
Adds concurrent coverage for SetLoaded and IsLoaded; barrier waits need timeout/cancellation handling and peer cancellation on worker failure. |
src/EFCore/Infrastructure/Internal/LazyLoader.cs |
Uses thread-safe loaded-state storage and adjusts loading-depth bookkeeping around the lock. |
Review effort: Lite
Code coverage overviewLanguages: C# C# / code-coverage
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. |
cincuranet
approved these changes
Nov 4, 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.
The existing test caught it.