Skip to content

fix(gateway): tighten renew and rotation lock release - #1599

Merged
kvinwang merged 1 commit into
nextfrom
fix/gateway-lock-identity
Nov 18, 2026
Merged

kvinwang merged 1 commit into
nextfrom
fix/gateway-lock-identity

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

release_lock could delete a successor's lease. A delete is stamped with local wall time and wins LWW over any lock stamped earlier:

  • Same-second re-acquire. The value (started_at seconds, started_by) is not unique; after a force release the same node can re-acquire in the same second and the stale holder's release matches. Adds a random nonce to CertRenewLock.
  • Absent key. An already released or force-released key fell through to the delete, which could beat a successor's lock not yet received. It now deletes only when the current value is ours.
  • Expired holder. A holder past its timeout could delete a lease a peer took over unseen. A peer takes over only once its own clock reads started_at + timeout, so a delete before the holder's clock reaches that point cannot beat the takeover, whatever the skew; past it the lease is now left to expire. release_*_lock takes the timeout, like acquire.

Compatibility: values are msgpack maps and nonce is #[serde(default)], so older gateways ignore it and older records decode with nonce = 0 (the legacy fixture now encodes the real two-field shape). Cross-node exclusion stays best-effort (no CAS in WaveKV).

Found by the Lean model of the lock (#1597, CertLock.lean).

release_lock could delete a successor's lease. A delete is stamped with
local wall time and wins LWW over any lock stamped earlier:

- The value (started_at seconds, started_by) is not unique: after a
  force release the same node can re-acquire in the same second, and
  the stale holder's release matched and deleted the successor's lock.
  Add a random nonce to the value.
- An absent key (already released or force-released) also fell through
  to the delete, which could beat a successor's lock not yet received.
  Delete only when the current value is ours.
- A holder past its timeout could delete a lease a peer had already
  taken over unseen. A peer takes over only once its clock reads
  started_at + timeout, stamping its lock no earlier, so a delete before
  the holder's clock reaches that point cannot beat it whatever the
  skew. Past it, leave the lease to expire; release now takes the
  timeout, like acquire.

The nonce is a serde-default field of a map-encoded value, so older
gateways ignore it and older records decode with nonce 0; the legacy
fixture now encodes the real two-field shape.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the fix/gateway-lock-identity branch from df99dbc to 50994ea Compare November 18, 2026 08:27
@kvinwang
kvinwang enabled auto-merge November 18, 2026 08:27
@kvinwang
kvinwang merged commit 2322682 into next Nov 18, 2026
20 of 21 checks passed
@kvinwang
kvinwang deleted the fix/gateway-lock-identity branch November 18, 2026 08:32
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.

1 participant