Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix Redis TryAcquireAsync handling for disconnected databases - #283

#283
Open
teesofttech wants to merge 2 commits into
madelson:mastermadelson/DistributedLock:masterfrom
teesofttech:fix/242-redis-unavailability-vs-lock-contentionteesofttech/DistributedLock:fix/242-redis-unavailability-vs-lock-contentionCopy head branch name to clipboard
Open

Fix Redis TryAcquireAsync handling for disconnected databases#283
teesofttech wants to merge 2 commits into
madelson:mastermadelson/DistributedLock:masterfrom
teesofttech:fix/242-redis-unavailability-vs-lock-contentionteesofttech/DistributedLock:fix/242-redis-unavailability-vs-lock-contentionCopy head branch name to clipboard

Conversation

@teesofttech

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 24, 2026 18:26
@teesofttech

teesofttech commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@madelson can you review this PR, please, for this issue: #242

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Redis TryAcquireAsync behavior in RedLock when one or more IDatabase instances are disconnected (where StackExchange.Redis may backlog operations instead of failing fast), ensuring disconnected cases surface promptly and correctly without masking real underlying faults.

Changes:

  • Update RedLockAcquire.WaitForAcquireAsync to properly propagate the synthetic “disconnected database” fault when it becomes decisive and no real faulted/canceled acquire tasks exist.
  • Adjust the disconnected-database decisiveness logic so a single disconnected database is immediately decisive in the single-server scenario.
  • Add CI tests covering: single-db disconnect throws, synthetic disconnect does not mask a real fault, and single-db contention returns null.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/DistributedLock.Tests/Tests/Redis/RedisDistributedLockTest.cs Adds targeted CI tests validating TryAcquireAsync outcomes for disconnected and contended Redis database scenarios.
src/DistributedLock.Redis/RedLock/RedLockAcquire.cs Fixes fault propagation for synthetic disconnect faults and refines decisiveness logic for single-database acquisition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@teesofttech

Copy link
Copy Markdown
Contributor Author

If you can help review this PR as well please @madelson

.ToArray();
if (faultingTasks.Length == 0)
{
await completed.ConfigureAwait(false); // propagate a synthetic disconnected fault

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this help and what is a synthetic disconnected fault?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original Redis operation is still waiting in the backlog, so it doesn’t appear in faultingTasks. When we detect that Redis is disconnected, we create a separate faulted task and assign it to completed. Awaiting it ensures the caller gets the useful RedisException rather than an empty AggregateException. I’ve updated the code comment to make that clearer.

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.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.