fix(auditdb): require matching anchor when refreshing an eid lease - #2120
Merged
Conversation
📊 Token Validation BenchmarkComparison of this PR against the base branch. 🟢 improvement · 🔴 regression · ➖ within ±1.0% noise.
|
AkramBitar
requested review from
Effi-S and
SaidAltury-ibm
and removed request for
HayimShaul
August 5, 2026 14:01
Contributor
|
LGTM. @AkramBitar. |
Effi-S
approved these changes
Aug 10, 2026
Signed-off-by: AkramBitar <akram@il.ibm.com>
AkramBitar
force-pushed
the
fix-2033-auditdb-locker-anchor
branch
from
August 10, 2026 16:01
a2b4e69 to
4697ba9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2033
The problem
The lease row for an enrollment ID could be overwritten whenever
owner = excluded.owner.owneris the replica ID — the same value for every audit on a node. So two concurrent audits on one node, for different transactions sharing an enrollment ID, both "acquired" it: the second overwrote the first's live row andAcquireLocksreturned success to both. The mistake only surfaced later, atAssertLocksHeldjust before the DB write.The fix
Also require the anchor to match, so a lease is only refreshed by the same owner and the same transaction:
Same owner, different anchor is now ordinary contention, retried until
acquireDeadline. Expired leases stay claimable, so crash recovery is unchanged.Tests
One query-shape test (no DB) and four against real Postgres: cross-anchor contention, same-anchor refresh, expired takeover, and four concurrent audits on one shared enrollment ID.
Against the old clause three fail — the concurrent one reporting all 4 audits as winners of the same lease. All pass with the fix under
-race;go vetandgolangci-lintclean.