Skip to content

Race condition in DefaultLockManagerย #26

@MarkCiliaVincenti

Description

@MarkCiliaVincenti

Hi,

There is a race condition in the DefaultLockManager.

Scenario:

  • thread A tries to lock on "123". It does not exist so it is created in the dictionary
  • thread B tries to lock on "123". It exists and is currently locked by A, so it waits for A to finish.
  • thread A finishes and removes the lock from the dictionary. Thread B enters the lock.
  • thread C tries to lock on "123". It does not exist in the dictionary since thread A removed it, therefore it will start processing concurrently to thread B for the same key "123".

I am the author of https://github.com/MarkCiliaVincenti/AsyncKeyedLock and can help you implement the necessary changes. The library would also help you reduce memory allocations by pooling instances of SemaphoreSlim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions