You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/20 15:18:32 UTC

[GitHub] [dubbo] AlbumenJ commented on a change in pull request #8701: [3.0] fix urlInvokerMap concurrent access issue

AlbumenJ commented on a change in pull request #8701:
URL: https://github.com/apache/dubbo/pull/8701#discussion_r712269371



##########
File path: dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
##########
@@ -222,7 +223,14 @@ private void refreshInvoker(List<URL> invokerUrls) {
             if (invokerUrls.isEmpty()) {
                 return;
             }
-            Map<URL, Invoker<T>> newUrlInvokerMap = toInvokers(invokerUrls);// Translate url list to Invoker map
+            
+            // can't use local reference because this.urlInvokerMap might be accessed at isAvailable() by main thread concurrently.
+            Map<URL, Invoker<T>> oldUrlInvokerMap = null;
+            if (this.urlInvokerMap != null) {
+                oldUrlInvokerMap = new LinkedHashMap<>(this.urlInvokerMap.size());

Review comment:
       Please consider load factor. `this.urlInvokerMap.size() / 0.75f + 1` would reduce one time resize.




-- 
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: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org