Copilot commented on code in PR #6294:
URL: https://github.com/apache/shenyu/pull/6294#discussion_r2785276618
##########
shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java:
##########
@@ -150,8 +150,11 @@ public void submit(final String selectorId, final
List<Upstream> upstreamList) {
// Check if the list is empty first to avoid unnecessary processing
if (actualUpstreamList.isEmpty()) {
- List<Upstream> existUpstreamList =
MapUtils.computeIfAbsent(UPSTREAM_MAP, selectorId, k -> Lists.newArrayList());
- removeAllUpstreams(selectorId, existUpstreamList);
+ List<Upstream> existUpstreamList = UPSTREAM_MAP.get(selectorId);
+ if (Objects.nonNull(existUpstreamList)) {
+ removeAllUpstreams(selectorId, existUpstreamList);
+ }
+ UPSTREAM_MAP.remove(selectorId);
Review Comment:
When `upstreamList` is empty, this branch removes upstreams based on
`UPSTREAM_MAP`, but `UPSTREAM_MAP` is populated from
`task.getHealthyUpstreamListBySelectorId(...)` (i.e., only healthy upstreams).
Any entries that only exist in the task's `unhealthyUpstream` map will not be
cleared, so a selector can retain stale unhealthy state after an empty event.
Consider clearing the task state directly (e.g.,
`task.triggerRemoveAll(selectorId)`) in addition to (or instead of) iterating
over `existUpstreamList`, and then remove the selectorId from `UPSTREAM_MAP`.
```suggestion
// Clear both cached upstreams and all health-check state for
this selector.
removeByKey(selectorId);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]