Commit 00bad6f
committed
fix(inflightload): prevent in-flight counter underflow on endpoint flap
The per-endpoint in-flight request/token counters are a +1/-1 ledger keyed
only by NamespacedName. PreRequest increments via the tracker map; release
(OnEvicted/releaseTokensEarly) re-looked-up the counter by endpoint ID and
decremented whatever instance was currently mapped. When an endpoint flaps
(NotReady -> EventDelete drops the counter -> rejoins under the same
NamespacedName -> new traffic recreates it), an in-flight request's release
landed on the recreated counter instead of the one it incremented, driving it
negative. This surfaced as negative pool saturation (observed ~ -1.4),
amplified when a pod crashed while holding many in-flight requests.
The existing registeredEndpoints pointer-identity guard only drops
out-of-order delete events for an already-replaced pointer; it does not cover
the normal flap sequence, so the underflow persisted.
- Capture a direct pointer to the exact *atomic.Int64 each request increments,
and decrement that instance on release. A stale release after a flap now
lands harmlessly on the orphaned counter; the live (recreated) counter only
ever sees its own request's +1/-1.
- Remove the now-unnecessary addIfPresent/decIfPresent 'is it present' guard.
- Add a decrementClamped CAS helper (mirroring the canonical
predictedlatency.decrementEndpointCounter primitive) that floors decrements
at 0 as defense-in-depth, so saturation can never go negative even under a
future regression.
- Add regression tests for the delete-then-recreate flap and the
crash-with-high-load drain (both fail without the fix), plus coverage for the
stale-delete guard. Tests use the realistic AddOrUpdate-then-Delete ordering.
Signed-off-by: Luke Van Drie <lukevandrie@google.com>1 parent 61c3aca commit 00bad6f
2 files changed
Lines changed: 219 additions & 43 deletions
File tree
- pkg/epp/framework/plugins/requestcontrol/dataproducer/inflightload
Lines changed: 57 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
143 | 147 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
148 | 152 | | |
149 | 153 | | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
161 | 164 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | 165 | | |
182 | 166 | | |
183 | | - | |
| 167 | + | |
184 | 168 | | |
185 | 169 | | |
186 | | - | |
| 170 | + | |
187 | 171 | | |
188 | 172 | | |
189 | 173 | | |
| |||
374 | 358 | | |
375 | 359 | | |
376 | 360 | | |
377 | | - | |
| 361 | + | |
378 | 362 | | |
379 | 363 | | |
380 | 364 | | |
381 | 365 | | |
382 | 366 | | |
383 | 367 | | |
384 | 368 | | |
385 | | - | |
| 369 | + | |
386 | 370 | | |
387 | 371 | | |
388 | | - | |
389 | | - | |
390 | | - | |
| 372 | + | |
| 373 | + | |
391 | 374 | | |
392 | 375 | | |
393 | 376 | | |
| |||
502 | 485 | | |
503 | 486 | | |
504 | 487 | | |
505 | | - | |
| 488 | + | |
506 | 489 | | |
507 | 490 | | |
508 | 491 | | |
| |||
635 | 618 | | |
636 | 619 | | |
637 | 620 | | |
638 | | - | |
639 | | - | |
| 621 | + | |
| 622 | + | |
640 | 623 | | |
641 | 624 | | |
642 | | - | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
643 | 630 | | |
644 | 631 | | |
645 | 632 | | |
646 | 633 | | |
647 | 634 | | |
648 | 635 | | |
649 | | - | |
| 636 | + | |
650 | 637 | | |
651 | 638 | | |
652 | 639 | | |
653 | 640 | | |
654 | 641 | | |
655 | 642 | | |
656 | 643 | | |
657 | | - | |
| 644 | + | |
658 | 645 | | |
659 | 646 | | |
660 | 647 | | |
661 | 648 | | |
662 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
663 | 677 | | |
664 | 678 | | |
665 | 679 | | |
| |||
Lines changed: 162 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
315 | 477 | | |
316 | 478 | | |
317 | 479 | | |
| |||
0 commit comments