Skip to content

Commit f46b97e

Browse files
authored
[#4643]fix: Nacos can't discover instances(#4644)
1 parent bf02a1b commit f46b97e

File tree

1 file changed

+4
-5
lines changed
  • service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos

1 file changed

+4
-5
lines changed

service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosDiscovery.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,24 @@ public boolean enabled(String application, String serviceName) {
7474
@Override
7575
public List<NacosDiscoveryInstance> findServiceInstances(String application, String serviceName) {
7676
try {
77+
// Get the instance first, and the Listener will not be executed for the first subscribe.
78+
List<Instance> instances = namingService.getAllInstances(serviceName, application, true);
79+
7780
AtomicBoolean result = SUBSCRIBES.computeIfAbsent(application,
7881
k -> new HashMap<>()).computeIfAbsent(serviceName, k -> new AtomicBoolean(true));
7982
if (result.get()) {
8083
synchronized (lock) {
8184
if (result.get()) {
8285
namingService.subscribe(serviceName, application, (event) -> {
83-
if (result.getAndSet(false)) {
84-
// ignore the first event.
85-
return;
86-
}
8786
if (event instanceof NamingEvent) {
8887
this.instanceChangedListener.onInstanceChanged(name(), application, serviceName,
8988
convertServiceInstanceList(((NamingEvent) event).getInstances(), application, serviceName));
9089
}
9190
});
91+
result.set(false);
9292
}
9393
}
9494
}
95-
List<Instance> instances = namingService.getAllInstances(serviceName, application, true);
9695
return convertServiceInstanceList(instances, application, serviceName);
9796
} catch (Exception e) {
9897
throw new IllegalStateException(e);

0 commit comments

Comments
 (0)