Skip to content

[BUG] Failover retries the same implicit-port upstream instead of excluding it #7475

Closed

Description

@Aias00

Description

DefaultRetryStrategy excludes the failed upstream by comparing each candidate upstream URL to needToExclude.getHost() + ":" + needToExclude.getPort(). For a URI such as http://localhost/test, Java reports getPort() == -1. ShenYu accepts upstream URLs without explicit ports and treats them as default ports in UpstreamCheckUtils, while Upstream.buildDomain() preserves the no-port form. As a result, a failed http://localhost/test attempt is compared as localhost:-1 against the configured upstream localhost, so the same upstream remains eligible for failover.

Location

  • shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/DefaultRetryStrategy.java:116
  • shenyu-common/src/main/java/org/apache/shenyu/common/utils/UpstreamCheckUtils.java:73
  • shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/entity/Upstream.java:471

Expected Behavior

Failover should normalize scheme, host, and effective port before excluding the failed upstream. If the only remaining candidate is the same failed upstream, failover should return the existing cannot-find-healthy-upstream error instead of retrying it.

Actual Behavior

Failover can select the same implicit-port upstream again. The scratch repro prints the same URI for the original attempt and the failover attempt:

http://localhost/test
http://localhost/test

Impact

Rules that configure host-only upstreams (localhost, example.com, https://example.com) can spend their failover retry budget on the same failed endpoint, reducing availability exactly when failover is expected to route around an unhealthy upstream.

Suggested Fix

Normalize both sides to a canonical upstream identity before comparing, for example scheme + host + effectivePort, where missing http and https ports resolve to 80 and 443. Add a regression test with current URI http://localhost/test and upstream URL localhost.

Evidence

Reviewed Revision And Validation

Apache ShenYu 2.7.2-SNAPSHOT, master at a89b6a2. Severity: medium. Confidence: high.

Actual retry-strategy scratch harness reproduced choosing the same implicit-port endpoint after failover.

Current source references:

  • shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/DefaultRetryStrategy.java:116
  • shenyu-common/src/main/java/org/apache/shenyu/common/utils/UpstreamCheckUtils.java:73
  • shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/entity/Upstream.java:471

No implementation fix or full deployed end-to-end validation was performed by this review. Source-flow and runtime evidence are distinguished above.

Activity

  1. github-actions commented on Oct 7, 2026

    @github-actions
    Contributor

    👋 Hello @yuluo-yx

    A new issue has been opened by @Aias00:

    Please review when you have time. Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature: http-proxytype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions