Aias00 opened a new issue, #6524: URL: https://github.com/apache/shenyu/issues/6524
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/shenyu/issues) and found no similar issues. ### Apache ShenYu Component shenyu-registry ### What happened `NacosInstanceRegisterRepository.compareInstances()` computes added and deleted instances with full `Instance.equals()` comparisons, then computes updated instances by matching `instanceId` and checking `!currentInstance.equals(previousInstance)`. Current code in `shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java`: ```java Set<Instance> addedInstances = currentInstances.stream() .filter(item -> !previousInstances.contains(item)) .collect(Collectors.toSet()); Set<Instance> deletedInstances = previousInstances.stream() .filter(item -> !currentInstances.contains(item)) .collect(Collectors.toSet()); Set<Instance> updatedInstances = currentInstances.stream() .filter(currentInstance -> Objects.nonNull(currentInstance.getInstanceId()) && previousInstances.stream().anyMatch(previousInstance -> StringUtils.isNotBlank(previousInstance.getInstanceId()) && currentInstance.getInstanceId().equals(previousInstance.getInstanceId()) && !currentInstance.equals(previousInstance))) .collect(Collectors.toSet()); ``` ShenYu currently uses Nacos client `2.2.4`. In that version, `com.alibaba.nacos.api.naming.pojo.Instance.equals()` compares `toString()` values, so changes to health, enabled flag, weight, metadata, and other fields make two objects unequal even when they represent the same `instanceId`. As a result, a property-only update for the same Nacos instance can be emitted as: 1. `ADDED`, because the changed current `Instance` is not contained in `previousInstances`. 2. `DELETED`, because the old `Instance` is not contained in `currentInstances`. 3. `UPDATED`, because the same `instanceId` exists and `equals()` is false. Downstream discovery consumers can receive contradictory events for one logical update. ### What you expected to happen For the same Nacos `instanceId`, a property-only change should emit one `UPDATED` event. Added and deleted detection should compare stable instance identity, not full mutable instance state. ### How to reproduce 1. Use Nacos discovery with ShenYu. 2. Register one instance and let `NacosInstanceRegisterRepository` store it in `watcherInstanceRegisterMap`. 3. Change only a mutable property of the same Nacos instance, such as weight or metadata, while keeping the same `instanceId`. 4. Trigger the Nacos listener and inspect events from `compareInstances()`. ### Debug logs _No response_ ### Environment Current master branch. ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! -- 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]
