Skip to content

Cache Concurrency Guard #117

Description

@JeremyCaney

Background

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

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

Metadata

Metadata

Assignees

Labels

Area: RepositoriesRelates to the `ITopicRepository` interface or one of its implementations.Priority: 1Severity 2: MajorStatus 5: CompleteTask is considered complete, and ready for deployment.Type: BugBehavior that is inconsistent with documented or expected behavior.Type: ImprovementImproves the functionality or interface of an existing feature.

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions