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

albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.1 by this push:
     new fdef33fab3 Copy on read to avoid concurrent issue (#10616)
fdef33fab3 is described below

commit fdef33fab3c140482baa6080347d983f16725bf5
Author: GuoHao <[email protected]>
AuthorDate: Thu Sep 15 14:06:04 2022 +0800

    Copy on read to avoid concurrent issue (#10616)
---
 .../apache/dubbo/common/config/ConfigurationUtils.java | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
index ab4ee4e14d..6daeb9fdf3 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
@@ -239,7 +239,11 @@ public final class ConfigurationUtils {
         }
 
         if (CollectionUtils.isNotEmptyMap(configMap)) {
-            for(Map.Entry<String, V> entry : configMap.entrySet()) {
+            Map<String,V> copy ;
+            synchronized (configMap){
+                copy = new HashMap<>(configMap);
+            }
+            for(Map.Entry<String, V> entry : copy.entrySet()) {
                 String key = entry.getKey();
                 V val = entry.getValue();
                 if (StringUtils.startsWithIgnoreCase(key, prefix)
@@ -276,7 +280,11 @@ public final class ConfigurationUtils {
         if (!prefix.endsWith(".")) {
             prefix += ".";
         }
-        for (Map.Entry<String, V> entry : configMap.entrySet()) {
+        Map<String,V> copy ;
+        synchronized (configMap){
+            copy = new HashMap<>(configMap);
+        }
+        for (Map.Entry<String, V> entry : copy.entrySet()) {
             String key = entry.getKey();
             if (StringUtils.startsWithIgnoreCase(key, prefix)
                 && key.length() > prefix.length()
@@ -311,7 +319,11 @@ public final class ConfigurationUtils {
         }
         Set<String> ids = new LinkedHashSet<>();
         for (Map<String, V> configMap : configMaps) {
-            for (Map.Entry<String, V> entry : configMap.entrySet()) {
+            Map<String,V> copy ;
+            synchronized (configMap){
+                copy = new HashMap<>(configMap);
+            }
+            for (Map.Entry<String, V> entry : copy.entrySet()) {
                 String key = entry.getKey();
                 V val = entry.getValue();
                 if (StringUtils.startsWithIgnoreCase(key, prefix)

Reply via email to