wujimin commented on a change in pull request #1789:
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1789#discussion_r431651062



##########
File path: 
foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
##########
@@ -45,11 +47,21 @@ public MicroserviceManager(AppManager appManager, String 
appId) {
   }
 
   public MicroserviceVersions getOrCreateMicroserviceVersions(String 
microserviceName) {
-    MicroserviceVersions microserviceVersions = 
versionsByName.computeIfAbsent(microserviceName, name -> {
-      MicroserviceVersions instance = new MicroserviceVersions(appManager, 
appId, microserviceName);
-      instance.pullInstances();
-      return instance;
-    });
+    // do not use ConcurrentHashMap computeIfAbsent for versionsByName
+    // because: when create MicroserviceVersions, one creation may depend on 
another
+    // MicroserviceVersions. And pullInstances will create a new 
MicroserviceVersions.
+    // Calling ConcurrentHashMap computeIfAbsent inside will get deadlock.
+    MicroserviceVersions microserviceVersions = 
versionsByName.get(microserviceName);

Review comment:
       hashmap is not thread safe, not only for write, but also for read




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to