Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
Divide attaches a P2C completion callback to the initially selected upstream. During failover, DefaultRetryStrategy.resend selects another upstream through LoadbalancerUtils.getForExchange. With at least two retry candidates, this enters P2C's doSelect and increments the new upstream's inflight counter.
The retry request is wrapped for circuit-breaker outcome accounting, but no P2C completion callback releases the retry upstream's increment. The outer Divide callback still captures the initial upstream. Repeated failovers therefore inflate counters on retry destinations and distort subsequent load estimates.
Expected Behavior
Every actual P2C attempt should have paired accounting on its own selected upstream, including success, failure and cancellation of failover attempts. Avoid double counting or releasing the wrong upstream.
Steps To Reproduce
Proposed HTTP integration scenario (not yet executed end-to-end):
- Configure Divide with
p2c, failover retry strategy, at least one retry and at least three healthy upstreams. - Make the initially selected upstream fail with a retry-eligible transport error.
- Leave at least two alternatives after exclusion so the retry takes the P2C multi-candidate path.
- Let the retry finish successfully, and wait for the outer request to terminate.
- Inspect the selected retry upstream's inflight counter. It was incremented by P2C selection but has no matching decrement on this request path.
- Repeat failovers and observe the accumulated overcount.
Evidence status: confirmed by source tracing at the commit below; this report does not claim an executed HTTP integration reproduction.
Anything else?
- P2C increment:
shenyu/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/spi/P2cLoadBalancer.java
Line 73 in 862f5e3
picked.getInflight().incrementAndGet(); - Retry selection and forwarding without P2C cleanup:
Lines 144 to 157 in 862f5e3
final Upstream upstream = LoadbalancerUtils.getForExchange(upstreamList, loadBalance, exchange); if (Objects.isNull(upstream)) { // no need to retry anymore return Mono.error(new ShenyuException("CANNOT_FIND_HEALTHY_UPSTREAM_URL_AFTER_FAILOVER")); } final URI newUri = RequestUrlUtils.buildRequestUri(exchange, upstream.buildDomain()); // in order not to affect the next retry call, newUri needs to be excluded exclude.add(newUri); final String breakerKey = UpstreamCircuitBreaker.buildKey(selectorId, upstream); return UpstreamCircuitBreaker.recordOutcome(httpClientPlugin .doRequest(exchange, exchange.getRequest().getMethod().name(), newUri, httpClientPlugin.getCachedRequestBody(exchange)) .timeout(duration, Mono.error(() -> new TimeoutException("Response took longer than timeout: " + duration))) .doOnError(e -> LOG.error(e.getMessage(), e)), breakerKey); } - Divide completion callback captures the original upstream:
Lines 198 to 209 in 862f5e3
*/ private Mono<Void> forwardWithCircuitBreaker(final ServerWebExchange exchange, final ShenyuPluginChain chain, final DivideRuleHandle ruleHandle, final String breakerKey, final Upstream upstream, final boolean probe) { Mono<Void> response = Mono.defer(() -> chain.execute(exchange)); if (ruleHandle.getLoadBalance().equals(P2C)) { response = response.doFinally(signalType -> responseTrigger(upstream)); } else if (ruleHandle.getLoadBalance().equals(SHORTEST_RESPONSE)) { long beginTime = System.currentTimeMillis(); response = response.doOnSuccess(e -> successResponseTrigger(upstream, beginTime)); } return probe ? response : UpstreamCircuitBreaker.recordOutcome(response, breakerKey); } - Related: [BUG] p2c inflight counter leaks on downstream cancellation (no doOnCancel/doFinally) #6733 fixed cancellation cleanup for the original forwarding path; the separate failover path still lacks per-attempt cleanup.
Environment
- ShenYu: master, 2.7.2-SNAPSHOT
- Commit:
862f5e37e894bd8cef85ef540a8629f313e9ecdf - Java 17
Activity
dmsolr commentedon Oct 22, 2026
Taking this. Will submit a PR shortly.
Root cause:
DefaultRetryStrategy.resendre-selects through the load balancer, which increments the retry upstream's P2C inflight, but no completion callback releases it (Divide's callback only captures the initial upstream). Fix releases the retry attempt's increment on success/failure/cancellation.Related (separate PR): #7974 (singleton selection path), #6733 (prior cancellation-cleanup fix).
dmsolr commentedon Oct 22, 2026
Fix submitted in #7982 (stacked on #7980 for #7974). Adds a P2C-only
doFinallyrelease of the retry upstream'sinflightinDefaultRetryStrategy.resend, covering success, failure and cancellation, plus regression tests for both the multi-candidate and singleton retry paths.fix: release P2C inflight on failover retry upstream (#7982)
Merge origin/master into fix/p2c-singleton-inflight
fix: pair P2C inflight accounting for singleton upstream selection (a…