Repository navigation
Description
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:116shenyu-common/src/main/java/org/apache/shenyu/common/utils/UpstreamCheckUtils.java:73shenyu-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
- Scratch repro:
.omx/reports/code-review-batch20/http/repro/FailoverImplicitPortRepro.java - Related existing distinction: [BUG] 5xx upstream responses never trigger failover retry (no error emitted) #6734 covers 5xx responses not entering failover; this issue happens after failover is already active and concerns failed-upstream exclusion identity.
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:116shenyu-common/src/main/java/org/apache/shenyu/common/utils/UpstreamCheckUtils.java:73shenyu-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
github-actions commentedon Oct 7, 2026
👋 Hello @yuluo-yx
A new issue has been opened by @Aias00:
Please review when you have time. Thank you! 🙏