Skip to content

fix(lock,election): add Lock/Campaign overloads that take an explicit lease - #321

Open
suleymanbyzt wants to merge 1 commit into
shubhamranjan:mainfrom
suleymanbyzt:fix/lock-election-explicit-lease
Open

fix(lock,election): add Lock/Campaign overloads that take an explicit lease#321
suleymanbyzt wants to merge 1 commit into
shubhamranjan:mainfrom
suleymanbyzt:fix/lock-election-explicit-lease

Conversation

@suleymanbyzt

Copy link
Copy Markdown

Campaign(name, value) and Lock(name) never set the lease field on the request.
etcd reads an unset lease as "make one for me": v3election/v3lock call
concurrency.NewSession (defaultSessionTTL = 60) and then immediately Orphan(),
which stops the keepalive. Nothing renews that lease, so the lock or the leadership
is dropped 60s after it is taken, with no signal to the caller.

measured on etcd 3.5.17, single node, no faults injected:

  • lease GrantedTTL 60, TTL just counts down 59 → 51 → ... → -1, never refreshed
  • at ~t=60 the key is deleted, holder still running, never called Unlock/Resign
  • a fresh client takes the same lock at t=64 in 0.00s, two holders at once
  • a caller waiting on that lock dies at 60s with mutex: session is expired
  • control case with an explicit lease + LeaseKeepAlive: still held after 40s with a
    10s TTL, contender still blocked. The server is fine, it's the missing lease.

docs/lock/api-reference.md already documents Lock(string, long leaseId, ...) and
docs/election/api-reference.md documents Campaign(string, long leaseId, string, ...).
Neither ever existed (git log -S is empty), so this implements the signatures you
already documented rather than inventing new ones. that's why Campaign takes the
lease before the value.

Lease-less overloads are [Obsolete], not removed. Docs updated to match the real API.

Tests don't sleep: they read the lease off the lock key and assert GrantedTTL, so the
new integration tests add about a second. The 60s wall-clock version is in
LeaseScopedOwnershipExpiryTests under Category=Slow, which neither CI filter picks
up (dotnet test --filter "Category=Slow" to run it).

Unit 356/356, Integration 63/63, no new warnings.

Left out on purpose: Lock(string, int leaseTtl) from the docs, since it needs the
client to own a lease's lifetime and keepalive your call, not mine. Also the
ByteString Campaign overload.

@github-actions github-actions Bot added the bug Something isn't working label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant