Commit e3530e9
committed
fix(sqs/throttle): address PR #679 review feedback (Codex P1/P2 + Gemini high/medium)
Six fixes from the first round of automated reviews on PR #679:
Codex P1 -- bucket reconciliation on stale config (sqs_throttle.go):
loadOrInit returned cached buckets without checking that capacity /
refillRate still match the queue's current Throttle config. After a
leadership change, a node retaining buckets from a prior leader term
would keep enforcing the prior term's limits even after a new
SetQueueAttributes had committed -- the invalidation only runs on the
leader that processed the commit, so a different leader's stale
buckets survive. Now compares cap/refill on every Load hit and
rebuilds (Delete + LoadOrStore) on mismatch.
Codex P1 -- invalidate only on actual throttle change (sqs_catalog.go,
sqs_throttle.go): cache invalidation in setQueueAttributes ran
unconditionally after every successful commit, including unrelated-
field updates and no-op writes. Result: any caller could silently
restore a noisy tenant's burst capacity by writing a no-op
SetQueueAttributes. Now gated on throttleAttributesPresent(in.Attributes)
which checks the request for any Throttle* key. Bucket reconciliation
above acts as the safety net if a future code path bypasses the gate.
Codex P2 -- attributesEqual covers Throttle (sqs_catalog.go):
CreateQueue idempotency relied on attributesEqual which did not
include Throttle*. A re-create with different limits was treated as
idempotent and silently kept the old limits. Now compares the full
Throttle struct via throttleConfigEqual; baseAttributesEqual extracted
to keep cyclop under the ceiling.
Gemini high -- thread throttle through existing meta load
(sqs_messages.go, sqs_throttle.go): chargeQueue did one Pebble read
per request even though the hot-path handlers (sendMessage,
receiveMessage) load the meta moments later. Added
chargeQueueWithThrottle that takes pre-loaded throttle config; both
hot-path handlers now load meta once and pass throttle in. Throttle
check now sits AFTER the QueueDoesNotExist branch so a missing queue
no longer consumes a token. Batch + delete handlers keep chargeQueue
(one extra meta read) -- low-QPS verbs where the simplification of
not pulling meta out of the retry loop is worth the per-call cost.
Gemini high -- move sweep off hot path (sqs.go, sqs_throttle.go):
maybeSweep ran the O(N) sync.Map.Range on whichever request was
unlucky enough to trigger the per-minute sweep, causing latency
spikes on many-queue clusters. Replaced with runSweepLoop on a
background ticker tied to s.reaperCtx (started in Run alongside the
existing message reaper, cleaned up by the same reaperCancel in
Stop). The hot-path charge() no longer calls into the sweep at all.
Gemini medium -- cap retry-after duration (sqs_throttle.go):
computeRetryAfter could compute a multi-day Retry-After (or worse,
overflow time.Duration arithmetic) for pathologically small
refillRate / large requested values. Capped at throttleRetryAfterCap
(1h, matching the bucket idle-evict window). Cap is applied before
the Duration multiplication so overflow is impossible.
New tests:
- TestBucketStore_ReconcilesBucketOnConfigChange pins the Codex P1
reconciliation contract.
- TestComputeRetryAfter_CapsAtMaximum pins the Gemini medium cap.
- TestThrottleAttributesPresent covers the request-gate helper used
by the conditional invalidation.
All tests pass under -race; golangci-lint clean.1 parent e105815 commit e3530e9
5 files changed
Lines changed: 252 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
643 | 650 | | |
644 | 651 | | |
645 | 652 | | |
| |||
650 | 657 | | |
651 | 658 | | |
652 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
653 | 681 | | |
654 | 682 | | |
655 | 683 | | |
| |||
1205 | 1233 | | |
1206 | 1234 | | |
1207 | 1235 | | |
1208 | | - | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
1215 | 1248 | | |
1216 | 1249 | | |
1217 | 1250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | 312 | | |
316 | 313 | | |
317 | 314 | | |
318 | | - | |
319 | | - | |
320 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
321 | 326 | | |
322 | 327 | | |
323 | 328 | | |
324 | 329 | | |
325 | 330 | | |
326 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
327 | 335 | | |
328 | 336 | | |
329 | 337 | | |
| |||
535 | 543 | | |
536 | 544 | | |
537 | 545 | | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | 546 | | |
542 | 547 | | |
543 | 548 | | |
| |||
559 | 564 | | |
560 | 565 | | |
561 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
562 | 574 | | |
563 | 575 | | |
564 | 576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
33 | 62 | | |
34 | 63 | | |
35 | 64 | | |
| |||
147 | 176 | | |
148 | 177 | | |
149 | 178 | | |
150 | | - | |
151 | 179 | | |
152 | 180 | | |
153 | 181 | | |
| |||
191 | 219 | | |
192 | 220 | | |
193 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
194 | 235 | | |
195 | 236 | | |
196 | 237 | | |
197 | 238 | | |
198 | 239 | | |
199 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
200 | 256 | | |
201 | 257 | | |
202 | 258 | | |
| |||
225 | 281 | | |
226 | 282 | | |
227 | 283 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
234 | 293 | | |
235 | 294 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
241 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
242 | 316 | | |
243 | 317 | | |
244 | 318 | | |
| |||
277 | 351 | | |
278 | 352 | | |
279 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
280 | 365 | | |
281 | 366 | | |
282 | 367 | | |
| |||
287 | 372 | | |
288 | 373 | | |
289 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
290 | 378 | | |
291 | 379 | | |
292 | 380 | | |
| |||
299 | 387 | | |
300 | 388 | | |
301 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
302 | 396 | | |
303 | 397 | | |
304 | 398 | | |
| |||
314 | 408 | | |
315 | 409 | | |
316 | 410 | | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
324 | 420 | | |
325 | 421 | | |
326 | 422 | | |
| |||
336 | 432 | | |
337 | 433 | | |
338 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
339 | 447 | | |
340 | 448 | | |
341 | 449 | | |
| |||
0 commit comments