Commit 7450621
committed
fix(auditdb): correct locker reconciliation, classification and cleanup
Review follow-up on the #2040 fix. Seven defects, each with a regression
test verified to fail without the corresponding change.
In-memory locker:
- The idempotent-re-acquire reconciliation was a read-modify-write over two
lock-free sync.Maps. Concurrent callers narrowing an anchor's ID set all
read the same stale record, all concluded the same ID was stale, and all
released its permit; x/sync/semaphore panics on over-release, so the
previous change traded the type-assertion panic it fixed for a new one
("semaphore: released more than held"). Reconciliation now runs under a
per-anchor lock. A single lock for the whole Locker would deadlock, since
AcquireLocks blocks on permits another anchor's release must hand over.
Anchor states are reference-counted and evicted, so the map does not grow
by one entry per audited transaction.
- An empty re-acquire recorded the empty set, releasing the locks the anchor
already held while returning nil: the caller kept believing it held them
and another anchor could take them immediately. Acquiring nothing now
leaves the anchor untouched, as the distributed locker already did.
- ErrLockContention was attached to every failed acquisition, so cancelling
a request on a completely free ID was reported and counted as a lock
conflict. The permit is now tried before blocking on it, so the sentinels
are attached only when the ID was genuinely held.
Postgres locker:
- The outcome was classified by which context expired first. acquireDeadline
defaults to a minute, so a request-scoped caller context is nearly always
shorter, and a caller-driven timeout returned a bare
context.DeadlineExceeded with no sentinel — this backend hardly ever
reported contention in production while the in-memory one always did.
Classification is now based on whether an attempt actually lost a race.
- A query killed by the acquire deadline carries context.DeadlineExceeded,
so a database outage was relabelled as contention with the original error
discarded, and isRetriableLockError then refused to retry it. The
underlying error is always joined in, and ErrLockAcquireTimeout is
attached only when the waiting budget is genuinely spent.
- The cleanup DELETE ran on a context that could neither be cancelled nor
time out, so it could block indefinitely on a saturated connection pool
or a conflicting row lock — leaving AcquireLocks hanging past the deadline
it promises to honour and leaking the goroutine on shutdown. releaseAnchor
now detaches and bounds, which also stops ReleaseLocks silently skipping
the delete on an already-cancelled context and stranding leases until TTL.
- A failed re-acquire released the anchor unconditionally, deleting the
lease rows of the live session it was re-acquiring for while leaving that
session's record and heartbeat running; the next renewal reported the
leases lost and the caller's next legitimate Append failed its pre-write
assertion. Cleanup runs only when the anchor has no live session.
The conformance suite gave the Postgres locker a 300ms acquire deadline,
shorter than its own wait contexts, which masked the misclassification
above; it now uses a production-shaped deadline.
Signed-off-by: AkramBitar <akram@il.ibm.com>1 parent bf27a8f commit 7450621
8 files changed
Lines changed: 648 additions & 79 deletions
File tree
- docs/services
- token/services/storage/auditdb/locker
- memory
- postgres
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
73 | 90 | | |
74 | 91 | | |
75 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
48 | 96 | | |
49 | 97 | | |
50 | 98 | | |
| |||
Lines changed: 74 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
71 | 78 | | |
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
75 | | - | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
200 | 207 | | |
201 | 208 | | |
202 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
203 | 217 | | |
204 | 218 | | |
205 | 219 | | |
| |||
208 | 222 | | |
209 | 223 | | |
210 | 224 | | |
211 | | - | |
| 225 | + | |
212 | 226 | | |
213 | 227 | | |
214 | 228 | | |
215 | 229 | | |
216 | 230 | | |
217 | 231 | | |
218 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 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 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
219 | 291 | | |
220 | 292 | | |
221 | 293 | | |
| |||
0 commit comments