Repository navigation
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Verdict: the accounting is right on the direct path, but the failover path leaks - please extend the fix
The core of this change is correct and the two increments do not double count:
ShortestResponseLoadBalancer.doSelectincrements for the normal selection path;DividePlugin.forwardSelectedincrements only in thecandidates.isProbe()branch, which bypassesLoadbalancerUtilsand thereforedoSelect. That is the same split P2C already relies on (increment insideP2cLoadBalancer.doSelect, plus a separate increment for the half-open probe), so the shape is consistent.releaseShortestResponseInflightusingupdateAndGet(current -> current > 0 ? current - 1 : 0)is a reasonable floor guard, and the test covers success, error and cancellation plus the already-zero case.
Blocking: retries re-select through the load balancer and leak an increment
DefaultRetryStrategy.resend picks the standby upstream through LoadbalancerUtils, so with shortestResponse it now runs ShortestResponseLoadBalancer.doSelect and increments that upstream. Divide's doFinally only holds the initially selected upstream, so:
- request fails -> failover selects
standby->standby.inflight++ - the response terminates ->
doFinallydecrements the original upstream
standby never gets its decrement back. Each failed-and-retried request leaks +1 on the standby, which permanently inflates succeededAverageElapsed * inflight and eventually drives all traffic away from a healthy upstream. This is exactly the defect #7982 fixes for P2C, and that PR's guard is scoped to P2C only:
if (LoadBalanceEnum.P2C.getName().equals(loadBalance)) {
retryResponse = retryResponse.doFinally(signalType -> upstream.getInflight().decrementAndGet());
}Please do one of:
- add the same release for
LoadBalanceEnum.SHORTEST_RESPONSEinDefaultRetryStrategy(mirroring #7982, including itsRetryStrategyTestcase), and note in both PRs that the guard must cover both load balancers; or - if you would rather land the retry part separately, say so explicitly in the description and keep this PR's scope to the non-retry path - but then the leak exists in
masteras soon as this merges, so option 1 is preferred.
Non-blocking
ShortestResponseLoadBalancerstill inheritsAbstractLoadBalancer.select, which short-circuits for a single upstream and never callsdoSelect. A single-upstream selector therefore never counts inflight, soshortestResponsesilently degrades to "always pick it" (harmless in that case, but inconsistent with #7980, which added an explicitselectoverride onP2cLoadBalancerfor exactly this reason). Consider the same override here for symmetry.- The new test's last assertion,
assertEquals(100, fast.getInflight().get() + slow.getInflight().get() - 2), relies on the twoset(1)baselines. It works, butfast.getInflight().get() + slow.getInflight().get()compared against2 + 100would read more obviously.
e623b24 to
b130d14
Compare
|
Thanks for the review @Aias00. Blocking: #7982 isn't on master yet (it was merged into Non-blocking: Branch rebased onto current master. Tests: |
b130d14 to
5a5372c
Compare
Aias00
left a comment
There was a problem hiding this comment.
The inflight accounting is correctly paired. I traced all four paths:
- Normal selection (>1 candidate):
ShortestResponseLoadBalancer.doSelectreturns throughtrackInflight(...)on every branch, so selection reserves exactly once. - Single candidate:
AbstractLoadBalancer.selectreturns beforedoSelect, so theselectoverride increments for that case only — guarded byupstreamList.size() == 1, so there is no double count whendoSelectdid run. - Half-open probe:
DividePlugin.forwardSelectedtakesbreakeredUpstreamList.get(0)directly without calling the load balancer, so the newSHORTEST_RESPONSEincrement there is needed and is not a duplicate (it sits inside thecandidates.isProbe()branch, not the normal path). - Sticky affinity hit:
resolveWithAffinityskips selection, so the added increment is again the only reservation.
Release side matches: forwardWithCircuitBreaker decrements once in doFinally, and DefaultRetryStrategy releases the standby attempt it selected, with updateAndGet(current -> current > 0 ? current - 1 : 0) preventing the counter from going negative if a signal fires twice.
This is consistent with the model already merged for P2C in #7980, and the SHORTEST_RESPONSE.equals(...) normalisation on the release branch is a nice touch.
LGTM.
Aias00
left a comment
There was a problem hiding this comment.
Code review of commit 5a5372c.
[P2] Pair the new selection reservation on the WebSocket path too
The attached finding was reproduced locally with the PR code and the relevant runtime handler/processor. This is targeted validation, not a full PR test-suite run.
|
Thanks @Aias00, good catch. Addressed in 94cc5db. The WebSocket path now uses the same session lifecycle wrapper (
An open session keeps the reservation until it terminates.
|
Aias00
left a comment
There was a problem hiding this comment.
The shortestResponse reservation is paired with release on HTTP, retry and WebSocket lifecycle paths. The earlier WebSocket leak finding is addressed by the inflight lifecycle handler, including termination/cancellation. No remaining actionable finding.
Validation: 72 focused load-balancer/HTTP/Divide tests passed; an additional WebSocket reactor run passed 15 tests (including 4 repeated load-balancer tests). No GitHub check rollup was available at the initial snapshot; required CI remains a merge gate. Apache RAT passed locally. Scope: source review and targeted verification; full integration/e2e suites were not run locally for this review.
ShortestResponse increments inflight when an upstream is selected, and Divide releases that count once on success, error, or cancellation without going negative. A historically fast upstream no longer keeps every request while its queue grows. Fixes apache#7973
Failover re-selects the standby through the load balancer, which increments its inflight. With a Divide attempt owner, that reservation moves to the standby and is released with the attempt: immediately on failure, or when the response body finishes on success. Without an owner, the retry completion releases the standby once, the same way P2C does.
Selection already reserved the upstream. Release that reservation when the session ends, or when the handshake finishes without starting a session.
94cc5db to
8f2faf0
Compare
Aias00
left a comment
There was a problem hiding this comment.
Stream Agent analysis
PR #7987 fixes inflight tracking for the shortestResponse load balancer algorithm. The bug was that shortestResponse did not increment inflight on selection, causing a fast upstream to accumulate all requests while its queue grew. The fix adds inflight increments at all selection points (normal selection, single-candidate fast path, half-open probes, sticky-session binding hits, and hash-based picks) and ensures exactly-once release via a guarded decrement that never goes negative. WebSocket upgrades now track the reservation through a state machine so the handshake and the long-lived session share one paired reservation.
Evidence
- Full diff (35,635 chars) read across all pages until has_more=false at offset 35635.
- CI passed: policy (7987), discover, and issue-spec-policy all completed successfully.
- Key fix verified: ShortestResponseLoadBalancer.select() now increments inflight for single candidate (line 45), DividePlugin adds reserveProbe() for half-open probes and increments for binding hits, releaseShortestResponseInflight() uses updateAndGet to prevent negative counts (line 552), WebSocketPlugin uses AtomicInteger state machine for exactly-once release.
Recommended next steps
Scope: captured diff and GitHub check metadata only; no local tests were executed.
Task: 044e8695-4ecb-4580-818b-87779b78db94 · Commit: 8f2faf03966af981f89c87deaf10959aef70a6f0
Review verdict: PASS
Complete diff coverage, all CI checks passed, and no concrete blocking defects. The implementation correctly addresses issue #7973 by ensuring shortestResponse tracks outstanding requests at every selection entry point and releases exactly once on all terminal paths (success, error, cancellation).
Publication: APPROVE (EXPLICIT_PASS)
Fixes #7973
shortestResponsenow accounts for outstanding requests. Selection incrementsinflight, and Divide decrements it exactly once on success, error, or cancellation, without going negative. A historically fast upstream no longer keeps every request while its queue grows. A half-open probe that skips the balancer incrementsinflightas well, so the release stays paired.Tests:
ShortestResponseLoadBalancerTest: the issue's repro (fast avg 10 vs slow avg 100, no completions between selections) no longer sends all requests to the fast upstream; each selection incrementsinflightonce.DividePluginTest: after success, error and cancel,inflightreturns to its baseline; a zero count stays zero.Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.