Skip to content

RedisLockRepository.AcquireAsync sets Status before checking if lock was acquired #32

Description

@Sarmkadan

In `RedisLockRepository.AcquireAsync`, the lock status is set to `Acquired` before the Redis SET NX operation:

```csharp
@lock.Status = Enums.LockStatus.Acquired; // Set before checking!
var success = await _database.StringSetAsync(key, value, expiry, When.NotExists);
```

If `StringSetAsync` returns `false` (lock already exists), the lock object's status is incorrectly set to `Acquired` even though acquisition failed. The caller receives `false` from the method but the lock object is in an inconsistent state.

Impact: Code that checks `@lock.Status` after a failed acquisition will incorrectly believe the lock was acquired.

Fix: Only set status to `Acquired` after confirming `success == true`.

Affected classes: `RedisLockRepository`
Affected file: `src/Backends/Redis/RedisLockRepository.cs`

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