You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/08/23 07:50:40 UTC

[GitHub] [skywalking] sonatype-lift[bot] commented on a change in pull request #7509: Support collection type in dynamic configuration core and add zookeeper implementation

sonatype-lift[bot] commented on a change in pull request #7509:
URL: https://github.com/apache/skywalking/pull/7509#discussion_r693740632



##########
File path: oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
##########
@@ -75,45 +88,127 @@ public void start() {
     }
 
     void configSync() {
-        Optional<ConfigTable> configTable = readConfig(register.keys());
+        singleConfigsSync();
+        groupConfigsSync();

Review comment:
       *THREAD_SAFETY_VIOLATION:*  Read/Write race. Non-private method `ConfigWatcherRegister.configSync()` indirectly reads without synchronization from container `this.groupConfigChangeWatcherRegister.register` via call to `Map.keySet()`. Potentially races with write in method `ConfigWatcherRegister.registerConfigChangeWatcher(...)`.
    Reporting because another access to the same memory occurs on a background thread, although this access may not.
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)

##########
File path: oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
##########
@@ -75,45 +88,127 @@ public void start() {
     }
 
     void configSync() {
-        Optional<ConfigTable> configTable = readConfig(register.keys());
+        singleConfigsSync();

Review comment:
       *THREAD_SAFETY_VIOLATION:*  Read/Write race. Non-private method `ConfigWatcherRegister.configSync()` indirectly reads without synchronization from container `this.singleConfigChangeWatcherRegister.register` via call to `Map.keySet()`. Potentially races with write in method `ConfigWatcherRegister.registerConfigChangeWatcher(...)`.
    Reporting because another access to the same memory occurs on a background thread, although this access may not.
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)

##########
File path: oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
##########
@@ -55,16 +56,28 @@ synchronized public void registerConfigChangeWatcher(ConfigChangeWatcher watcher
         }
 
         WatcherHolder holder = new WatcherHolder(watcher);
-        if (register.containsKey(holder.getKey())) {
+        if (singleConfigChangeWatcherRegister.containsKey(
+            holder.getKey()) || groupConfigChangeWatcherRegister.containsKey(holder.getKey())) {
             throw new IllegalStateException("Duplicate register, watcher=" + watcher);
         }
-        register.put(holder.getKey(), holder);
+
+        switch (holder.getWatcher().getWatchType()) {
+            case SINGLE:
+                singleConfigChangeWatcherRegister.put(holder.getKey(), holder);
+                break;
+            case GROUP:
+                groupConfigChangeWatcherRegister.put(holder.getKey(), holder);
+                break;
+            default:
+                throw new IllegalArgumentException(
+                    "Unexpected watch type of ConfigChangeWatcher " + watcher.toString());
+        }
     }
 
     public void start() {
         isStarted = true;
 
-        LOGGER.info("Current configurations after the bootstrap sync." + LINE_SEPARATOR + register.toString());
+        LOGGER.info("Current configurations after the bootstrap sync." + LINE_SEPARATOR + singleConfigChangeWatcherRegister.toString());

Review comment:
       *THREAD_SAFETY_VIOLATION:*  Read/Write race. Non-private method `ConfigWatcherRegister.start()` indirectly reads without synchronization from container `this.singleConfigChangeWatcherRegister.register` via call to `Map.forEach(...)`. Potentially races with write in method `ConfigWatcherRegister.registerConfigChangeWatcher(...)`.
    Reporting because another access to the same memory occurs on a background thread, although this access may not.
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)




-- 
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@skywalking.apache.org

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