This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new f46b97e96 [#4643]fix: Nacos can't discover instances(#4644)
f46b97e96 is described below

commit f46b97e96d209a9f3bb5bb9ab4097e5e05ea910b
Author: myhaiting <[email protected]>
AuthorDate: Tue Dec 17 15:07:55 2024 +0800

    [#4643]fix: Nacos can't discover instances(#4644)
---
 .../org/apache/servicecomb/registry/nacos/NacosDiscovery.java    | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git 
a/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosDiscovery.java
 
b/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosDiscovery.java
index 004415ca9..bd41ad539 100644
--- 
a/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosDiscovery.java
+++ 
b/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosDiscovery.java
@@ -74,25 +74,24 @@ public class NacosDiscovery implements 
Discovery<NacosDiscoveryInstance> {
   @Override
   public List<NacosDiscoveryInstance> findServiceInstances(String application, 
String serviceName) {
     try {
+      // Get the instance first, and the Listener will not be executed for the 
first subscribe.
+      List<Instance> instances = namingService.getAllInstances(serviceName, 
application, true);
+
       AtomicBoolean result = SUBSCRIBES.computeIfAbsent(application,
           k -> new HashMap<>()).computeIfAbsent(serviceName, k -> new 
AtomicBoolean(true));
       if (result.get()) {
         synchronized (lock) {
           if (result.get()) {
             namingService.subscribe(serviceName, application, (event) -> {
-              if (result.getAndSet(false)) {
-                // ignore the first event.
-                return;
-              }
               if (event instanceof NamingEvent) {
                 this.instanceChangedListener.onInstanceChanged(name(), 
application, serviceName,
                     convertServiceInstanceList(((NamingEvent) 
event).getInstances(), application, serviceName));
               }
             });
+            result.set(false);
           }
         }
       }
-      List<Instance> instances = namingService.getAllInstances(serviceName, 
application, true);
       return convertServiceInstanceList(instances, application, serviceName);
     } catch (Exception e) {
       throw new IllegalStateException(e);

Reply via email to