Skip to content

fix(httpclient): handle missing upstream list during failover - #7483

Merged
Aias00 merged 3 commits into
apache:masterfrom
lymerin:7476
Oct 11, 2026
Merged

Aias00 merged 3 commits into
apache:masterfrom
lymerin:7476

Conversation

@lymerin

@lymerin lymerin commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7476

Problem

With the failover retry strategy explicitly selected (the default is current) and the rule's default retry count of 3, an in-flight request can retry after its selector’s upstream cache entry has been removed.

The removal path is removeByKey → triggerRemoveAll → healthyUpstream.remove. It is reached when a selector is deleted, discovery upstream data is deleted, or an upstream update supplies an empty list.

UpstreamCacheManager.findUpstreamListBySelectorId() then returns null, but DefaultRetryStrategy calls .stream() directly on that result.

Health-check status changes do not remove the key: they remove individual list elements, leaving an empty list that already follows the controlled 503 exhaustion path.

Both WebClient and Netty convert upstream 5xx responses into error signals in failover mode, so a connection failure or timeout is not required.

Impact

The NPE escapes the existing error mappings and reaches GlobalErrorHandler, producing HTTP 500 with the default JSON response {"code":500,"message":"Internal Server Error"} and invoking AlarmSender.alarmMediumCritical("ShenYu-Gateway-Global-Error", ...).

Both HTTP client plugins are affected when using DefaultRetryStrategy to retry after a cache-entry removal.

The fix restores the existing HTTP 503 response with reason CANNOT_FIND_HEALTHY_UPSTREAM_URL_AFTER_FAILOVER. The global handler also invokes its alarm for this controlled response.

Changes

  • Store the latest upstream list in a local variable and check it for null before streaming.
  • Return the existing CANNOT_FIND_HEALTHY_UPSTREAM_URL_AFTER_FAILOVER exception for a missing list.
  • Preserve existing upstream filtering, empty-list handling, load balancing, and retry behavior.
  • Add two regression tests covering:
    • A missing upstream list with the failover retry count set to 3, verifying that no additional upstream request occurs.
    • A WebClient 500 response after removing a previously populated real cache entry, verifying the actual 5xx conversion path and that no additional upstream request or downstream chain execution occurs.

Validation

  • Before the fix, both new regression tests failed their expectErrorSatisfies assertions because they received NullPointerException instead of ResponseStatusException; after the fix, all 41 module tests passed with zero failures or errors.
  • Checkstyle passed with zero violations, and the full local clean install passed.

Checklist

Make sure that:

@lymerin lymerin closed this Oct 7, 2026
@lymerin lymerin reopened this Oct 7, 2026
Aias00
Aias00 previously approved these changes Oct 8, 2026

@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 7f0954df8cb0.

The failover retry path now handles a missing upstream list as an exhausted failover instead of throwing a null-pointer error. 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,WebClientPluginTest -Dsurefire.failIfNoSpecifiedTests=false -Drat.skip=true -Djacoco.skip=true -DskipRemoteResources=true -Dmaven.javadoc.skip=true

@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.

Summary

Correct fix. When findUpstreamListBySelectorId returns null during failover, DefaultRetryStrategy.resend now fails cleanly with ShenyuException, which is mapped to a 503 ResponseStatusException by the existing onErrorMap (DefaultRetryStrategy.java:89) — instead of blowing up with an NPE. Both added tests assert the 503 path.

Approving.

@Aias00
Aias00 merged commit 0e9ce08 into apache:master Oct 11, 2026
28 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 throws NPE when the selector upstream list disappears before retry

2 participants