Skip to content

Fix(redis): Makes redis leader-election lease duration configurable - #157

Open
MongareAlex wants to merge 10 commits into
steingran:mainfrom
MongareAlex:fix/configurable-redis_leader_ttl
Open

MongareAlex wants to merge 10 commits into
steingran:mainfrom
MongareAlex:fix/configurable-redis_leader_ttl

Conversation

@MongareAlex

@MongareAlex MongareAlex commented Oct 30, 2026 •

Copy link
Copy Markdown

LeaseDuration now controls the TTL on both initial acquire and subsequent heartbeat renewals, so one setting governs the full lease window.

Behavior change: before this PR, the initial lease TTL was lockTimeout (30s default from LeaderElectionOptions). It is now LeaseDuration (2 min default).

Fixes #156

The Redis provider previously used a hardcoded 120-second TTL for the
leadership key. A fixed 120s left no room to tune for this.

Add RedisLeaderElectionOptions.LeaseDuration (default: 2 minutes) and
thread it through acquire and renew paths in place of the literal.
The Redis provider previously used a hardcoded 120-second TTL for the
leadership key. A fixed 120s left no room to tune for this.

Add RedisLeaderElectionOptions.LeaseDuration (default: 2 minutes) and
thread it through acquire and renew paths in place of the literal.

Fixes steingran#156

@steingran steingran left a comment

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.

Thanks for picking up #156! Making the renewal TTL configurable is a good change, and keeping the 2-minute default means existing users see no difference.

Main issue to fix before merge: LeaseDuration is only used when the leader renews the key. When the key is first created in TryAcquireLeadershipAsync, the TTL still comes from the lockTimeout argument (LeaderElectionOptions.LockTimeout, 30 s by default). The PR description says both paths are covered, but only the renew path changed.

Because of this, the new integration test TryAcquireLeadership_WithShortLeaseDuration_ShouldExpireWithoutHeartbeat will fail when it runs against Redis: the key is created with a 5-minute TTL, so it still exists after the 3-second wait.

Summary of the inline comments:

  1. Use LeaseDuration on acquire too (or, if renewal-only is the intent, update the PR description and the test).
  2. Make the integration test match what the code does.
  3. Add a test for the renew path. It is the only production line that changed, and no test covers it yet.
  4. Add unit tests for the new LeaseDuration <= 0 check.
  5. The doc says LeaseDuration must be larger than HeartbeatInterval, but nothing checks this.
  6. A few small formatting nits (one-click suggestions).

Happy to answer questions on any of these.

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.75%. Comparing base (ca22cd9) to head (f371308).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #157      +/-   ##
==========================================
+ Coverage   72.53%   72.75%   +0.21%     
==========================================
  Files          65       65              
  Lines        4974     4977       +3     
  Branches      607      608       +1     
==========================================
+ Hits         3608     3621      +13     
+ Misses       1155     1145      -10     
  Partials      211      211              
Files with missing lines Coverage Δ
...ders/MultiLock.Redis/RedisLeaderElectionOptions.cs 100.00% <100.00%> (ø)
...ers/MultiLock.Redis/RedisLeaderElectionProvider.cs 78.57% <100.00%> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca22cd9...f371308. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Redis TTL not configurable?

3 participants