Pre-check
- [x] I am sure that all the content I provide is in English.
Search before asking
- [x] I had searched in the issues and found no similar issues.
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
dubbo3.3.5 nacos2.2.4
Steps to reproduce this issue
Shut down the virtual machine where the abnormal dubbo provider is located and restart this virtual machine and the dubbo provider. Then the nacos server will push two identical registration messages, but with different timestamps. The duplicate removal of refreshinvoker in seviceDiscoveryRegistryDirectory will not delete the duplicate invoker because the received url object type is instanceAddressUrl, and its equals method will determine whether the internal instance is equal. https://github.com/apache/dubbo/pull/15060 cannot resolve the problem
What you expected to happen
Remove duplicated invokers in registry notification
Anything else
No response
Are you willing to submit a pull request to fix on your own?
- [x] Yes I am willing to submit a pull request on my own!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Comment From: zrlw
do you mean the equals
method of DefaultServiceInstance should not check timestamp?
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof DefaultServiceInstance)) {
return false;
}
DefaultServiceInstance that = (DefaultServiceInstance) o;
boolean equals = Objects.equals(getServiceName(), that.getServiceName())
&& Objects.equals(getHost(), that.getHost())
&& Objects.equals(getPort(), that.getPort());
for (Map.Entry<String, String> entry : this.getMetadata().entrySet()) {
if (entry.getKey().equals(EXPORTED_SERVICES_REVISION_PROPERTY_NAME)) {
continue;
}
// don't compare timestamp?
if (entry.getKey().equals("timestamp") {
continue;
}
if (entry.getValue() == null) {
equals = equals && (entry.getValue() == that.getMetadata().get(entry.getKey()));
} else {
equals = equals && entry.getValue().equals(that.getMetadata().get(entry.getKey()));
}
}
return equals;
}
Comment From: zrlw
by the way, these codes at DefaultServiceInstance#equals
should be optimized like this
@Override
public boolean equals(Object o) {
...
for (Map.Entry<String, String> entry : this.getMetadata().entrySet()) {
...
if (entry.getValue() == null) {
if (null != that.getMetadata().get(entry.getKey())) {
return false;
}
} else {
if (!entry.getValue().equals(that.getMetadata().get(entry.getKey())) {
return false;
}
}
}
return true;
}