Commit 5aced16
committed
fix(auditdb): align auditor EID locker semantics across backends
The auditor takes short-lived locks on the enrollment IDs a request touches,
through a Locker chosen from configuration: memory for a single replica,
postgres for a cluster. The two were not interchangeable, so the same auditor
code was correct on one deployment and broken on the other. The Locker
interface now documents the contract its implementations are held to — it had
none, which is how they drifted — and locker/conformance_test.go exercises
every expectation against both backends.
The three findings in #2040:
- AssertLocksHeld detects lost locks, not absent ones. An anchor holding
nothing succeeds, so a request whose inputs and outputs yield no enrollment
IDs can be appended under postgres too, as can an auditor that validates and
appends without calling Audit (the dvp and nft views).
- The memory locker keeps enrollment-ID semaphores and per-anchor bookkeeping
in separate maps. One shared sync.Map, keyed by unconstrained strings of
unrelated provenance, let an anchor equal to an enrollment ID return the
other namespace's value type and panic on the assertion.
- The auditor's retry no longer nests inside the locker's own waiting budget:
ErrLockAcquireTimeout is final, so worst-case blocking for one audit is
acquireDeadline rather than MaxRetries times it. The inner poll loop is
exponential and jittered instead of a flat 100ms, which cuts round trips
from hundreds to a few dozen and stops contending replicas retrying in
lockstep.
And the defects that aligning them surfaced:
- A live anchor's EID set may shrink or stay the same, never grow. Deadlock
freedom rests on taking shared IDs in one canonical order, and that order
only covers the IDs of a single call, so an anchor that kept earlier locks
while waiting for new ones held locks outside it: two anchors widening into
each other's IDs waited on each other forever, and permanently, since the
anchor's lock is held across the blocking acquire and so blocked the release
that would have broken the cycle. Widening now fails with ErrLockSetWidened.
- Postgres releases the leases a narrowing re-acquisition drops. Its upsert
only inserted, and both AssertLocksHeld and the heartbeat require an exact
row count per anchor, so each leftover row rejected the next write, killed
the heartbeat, and then expired into another replica's hands.
- unlockAnchor no longer decides eviction from an emptiness flag sampled
before the anchor's lock was released, which let an anchor still holding
permits be dropped and those permits be stranded for the process lifetime.
- Each backend bounds its own waiting, so a caller that passes no deadline
still gets an answer and a spent budget is reported as
ErrLockAcquireTimeout.
- Failure classification is based on whether an attempt actually lost a race
for an ID, not on which context expired first. The underlying error is
joined in, so a database outage is reported as itself; a caller's own
cancellation on a free ID is not a conflict; a locker's own expired budget
is retriable while the caller's context is live; and only ErrLockContention
counts towards auditor_audit_lock_conflicts_total.
- releaseAnchor detaches from the caller's context so a deferred release on an
already-cancelled context still runs, and bounds itself so a stuck DELETE
cannot outlive the deadline AcquireLocks promises. A failed re-acquisition
no longer releases an anchor that already holds a live session.
Fixes #2040
Signed-off-by: AkramBitar <akram@il.ibm.com>1 parent 3552482 commit 5aced16
20 files changed
Lines changed: 2228 additions & 161 deletions
File tree
- docs
- services
- token/services
- auditor
- storage/auditdb
- locker
- dedup
- errs
- memory
- postgres
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
322 | 332 | | |
323 | 333 | | |
324 | 334 | | |
325 | 335 | | |
326 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
327 | 339 | | |
328 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
329 | 346 | | |
330 | 347 | | |
331 | 348 | | |
| |||
810 | 827 | | |
811 | 828 | | |
812 | 829 | | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
813 | 838 | | |
814 | 839 | | |
815 | 840 | | |
| |||
924 | 949 | | |
925 | 950 | | |
926 | 951 | | |
| 952 | + | |
927 | 953 | | |
928 | 954 | | |
929 | 955 | | |
| |||
933 | 959 | | |
934 | 960 | | |
935 | 961 | | |
936 | | - | |
937 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
938 | 965 | | |
939 | 966 | | |
940 | 967 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
86 | 117 | | |
87 | 118 | | |
88 | 119 | | |
| |||
96 | 127 | | |
97 | 128 | | |
98 | 129 | | |
99 | | - | |
100 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
101 | 133 | | |
102 | 134 | | |
103 | 135 | | |
| |||
113 | 145 | | |
114 | 146 | | |
115 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
116 | 154 | | |
117 | 155 | | |
118 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
182 | 188 | | |
183 | 189 | | |
184 | 190 | | |
| |||
193 | 199 | | |
194 | 200 | | |
195 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
196 | 209 | | |
197 | 210 | | |
198 | 211 | | |
| |||
204 | 217 | | |
205 | 218 | | |
206 | 219 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
211 | 227 | | |
| 228 | + | |
| 229 | + | |
212 | 230 | | |
213 | 231 | | |
214 | 232 | | |
215 | 233 | | |
216 | 234 | | |
217 | 235 | | |
218 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
219 | 261 | | |
220 | 262 | | |
221 | 263 | | |
| |||
0 commit comments