Skip to content

[BUG] P2C failover retries increment upstream inflight without matching completion cleanup #7975

Closed

Description

@Aias00

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):

  1. Configure Divide with p2c, failover retry strategy, at least one retry and at least three healthy upstreams.
  2. Make the initially selected upstream fail with a retry-eligible transport error.
  3. Leave at least two alternatives after exclusion so the retry takes the P2C multi-candidate path.
  4. Let the retry finish successfully, and wait for the outer request to terminate.
  5. Inspect the selected retry upstream's inflight counter. It was incremented by P2C selection but has no matching decrement on this request path.
  6. 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:
  • Retry selection and forwarding without P2C cleanup:
    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:
    */
    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

  1. added
    type: bug
    on Oct 22, 2026
  2. self-assigned this
    on Oct 22, 2026
  3. dmsolr commented on Oct 22, 2026

    @dmsolr
    Member

    Taking this. Will submit a PR shortly.

    Root cause: DefaultRetryStrategy.resend re-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).

  4. dmsolr commented on Oct 22, 2026

    @dmsolr
    Member

    Fix submitted in #7982 (stacked on #7980 for #7974). Adds a P2C-only doFinally release of the retry upstream's inflight in DefaultRetryStrategy.resend, covering success, failure and cancellation, plus regression tests for both the multi-candidate and singleton retry paths.

  5. added a commit that references this issue on Oct 23, 2026
    6e47672
  6. added a commit that references this issue on Oct 26, 2026
    052a036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions