Skip to content

Fix race condition in ModuleEngineRegistry with ReaderWriterLockSlim - #132

Merged
SamuelMcAravey merged 3 commits into
codex/2025-12-21-refactor-solution-for-transport-agnostic-modules-1ziys6from
copilot/sub-pr-129
Dec 22, 2025
Merged

Fix race condition in ModuleEngineRegistry with ReaderWriterLockSlim#132
SamuelMcAravey merged 3 commits into
codex/2025-12-21-refactor-solution-for-transport-agnostic-modules-1ziys6from
copilot/sub-pr-129

Conversation

Copilot AI commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

ModuleEngineRegistry had a race condition where concurrent Register() or Reset() calls could modify the Engines dictionary while GetEngines(), FindWebhookEngine(), or FindById() were iterating over it, potentially causing InvalidOperationException.

Changes

  • Added ReaderWriterLockSlim to protect all registry operations
    • Write locks for Register() and Reset() (mutating operations)
    • Read locks for GetEngines(), FindWebhookEngine(), and FindById() (query operations)
    • Simplified GetEngines() to use single read lock instead of per-list locks

The read lock prevents all writes during enumeration, eliminating the race condition while maintaining efficient concurrent reads.

public static IReadOnlyCollection<IModuleEngineDescriptor> GetEngines()
{
    RegistryLock.EnterReadLock();
    try
    {
        // The read lock ensures no modifications occur during enumeration
        return Engines.Values.SelectMany(list => list).ToArray();
    }
    finally
    {
        RegistryLock.ExitReadLock();
    }
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
@SamuelMcAravey
SamuelMcAravey marked this pull request as ready for review December 22, 2025 04:50
Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
Copilot AI changed the title [WIP] Update engine descriptors and typed navigation Fix race condition in ModuleEngineRegistry with ReaderWriterLockSlim Dec 22, 2025
Copilot AI requested a review from SamuelMcAravey December 22, 2025 04:54
@SamuelMcAravey
SamuelMcAravey merged commit c73ba14 into codex/2025-12-21-refactor-solution-for-transport-agnostic-modules-1ziys6 Dec 22, 2025
@SamuelMcAravey
SamuelMcAravey deleted the copilot/sub-pr-129 branch December 22, 2025 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants