Skip to content

fix(httpclient): stop failover retrying the same failed upstream when… - #7489

Merged
Aias00 merged 1 commit into
apache:masterfrom
lymerin:7475
Oct 8, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
lymerin:7475

Conversation

@lymerin

@lymerin lymerin commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7475

Problem

With DefaultRetryStrategy, failover enabled, and retries configured, a failed upstream without an explicit port is never excluded.

For the valid upstream configuration localhost, ShenYu builds a request such as http://localhost/test. HTTP uses port 80, but Java's URI.getPort() returns -1 because the port was omitted from the URI.

The exclusion check then constructs getHost() + ":" + getPort() and compares it directly with the configured upstream:

Failed request identity: localhost:-1
Configured upstream:     localhost

These strings do not match, so the failed upstream remains eligible for every retry. HTTPS upstreams with omitted ports have the same problem.

Impact

  • Failover can repeatedly request the same failed endpoint, consuming retries instead of selecting another upstream or returning the existing CANNOT_FIND_HEALTHY_UPSTREAM_URL_AFTER_FAILOVER error.

  • For a single upstream that keeps timing out, this returns 504 instead of the existing 503 exhaustion response.

Changes

  • Parse candidate upstreams through buildDomain() and compare scheme, host, and effective port, using UriUtils.getActualPort().
  • Exclude path and query parameters from upstream identity.
  • Preserve the existing retry flow, latest-cache lookup, load balancing, request-body replay, and error mappings.
  • Add two regression test groups covering:
    • The issue's host-only HTTP upstream, HTTP/HTTPS implicit/explicit default-port equivalence, and explicit ports with different paths and queries.
    • Selection of upstreams with different hosts, ports, or schemes, verifying the actual request URI.

Validation

  • All 46 HTTP client module tests passed, with zero failures, errors, or skipped tests.
  • Checkstyle reported zero violations.

Checklist

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head a3e4574856e2.

Failover retry exclusion now recognizes the same upstream across implicit and explicit default ports, while still allowing different ports or schemes. No blocking issue found.

Validation: exact-head targeted Maven reactor tests passed on Java 17.

./mvnw -pl shenyu-plugin/shenyu-plugin-httpclient -am test -Dtest=RetryStrategyTest -Dsurefire.failIfNoSpecifiedTests=false -Drat.skip=true -Djacoco.skip=true -DskipRemoteResources=true -Dmaven.javadoc.skip=true

@Aias00
Aias00 merged commit c5099d1 into apache:master Oct 8, 2026
23 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants