You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lazy loading introduces a concurrency bug into the shared CachedTopicRepository singleton where reading a topic's children (or other properties) used to be a safe read, but now triggers an in-place merge with no synchronization, so two concurrent requests hitting the same unloaded topic can throw a InvalidOperationException or corrupt the state.
Solution
The fix is a per-topic async gate (not a global lock) that serializes loads of the same topic while leaving unrelated topics fully concurrent, with the gate safely reclaimed once a topic is fully loaded (relying on the fact these boundaries only ever progress from LoadState.NotLoaded to LoadState.Loaded).
Create unit test to expose the issue
Per-topic SemaphoreSlim gate with double-checked-locking pattern in EnsureLoaded()
Note: This explicitly excludes associations (i.e., relationships and references), since their LoadState is dynamic; those will be handled separately (#128).
Activity
CachedTopicRepository#111TopicIndexcache #116TopicIndexcache #116TopicIndexcache #116ITopicRepository.Load()#120Merge pull request #145 from OnTopicCMS/feature/ITopicRepository-lazy…
JeremyCaney commentedon Aug 9, 2026
Merged with 362b9fb:
BlockingStubLazyLoadingTopicRepositoryto test concurrency issues (2875725)SemaphoreSlimgate with double-checked-locking pattern inEnsureLoaded()EnsureLoaded()concurrency gate per topic (5779261)