[ISSUE #6144] 修复通过 nacos 发现下游服务时,下游服务重启后,会将旧的IP覆盖新的IP。导致通过shenyu调用下游服务报错Can not find healthy upstream url, please check your configuration!#6201
Merged
Aias00 merged 4 commits intoapache:masterfrom Oct 21, 2025
Conversation
…listening to the UpstreamList, which results in errors with valid instances. 1. 缓存实例逻辑修复 2. 新增通过 selectorId 获取健康实例方法 3. weight 支持 set 方法 4. 重写 Upstream equals 方法(去除 weight 参与相等校验) issues: apache#6144 apache#6144
1 task
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where Nacos service discovery in ShenYu would incorrectly retain old IPs after downstream service restarts, causing "Can not find healthy upstream url" errors. The fix improves the upstream instance caching logic to properly handle service restarts and IP changes.
Key changes:
- Modified
Upstream.equals()to exclude weight from equality checks, preventing duplicate instances with different weights - Added
setWeight()method to allow weight updates for existing upstream instances - Refactored
UpstreamCacheManager.submit()to properly handle offline instances and update weights for existing upstreams
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Upstream.java | Made weight field mutable and excluded it from equals() comparison to support weight updates without affecting instance identity |
| UpstreamCheckTask.java | Added method to retrieve healthy upstream list by selector ID for cache synchronization |
| UpstreamCacheManager.java | Rewrote submit() logic to properly handle offline instances, update weights, and sync with healthy upstream list |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...yu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
Outdated
Show resolved
Hide resolved
...yu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
Outdated
Show resolved
Hide resolved
...yu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
Outdated
Show resolved
Hide resolved
…er/cache/UpstreamCacheManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…er/cache/UpstreamCacheManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…er/cache/UpstreamCacheManager.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Aias00
approved these changes
Oct 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复通过 nacos 发现下游服务时,下游服务重启后,会将旧的IP覆盖新的IP。导致通过shenyu调用下游服务报错Can not find healthy upstream url, please check your configuration!
issues: #6144 #6144
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.