You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by "Aias00 (via GitHub)" <gi...@apache.org> on 2026/08/04 02:48:51 UTC

[I] [BUG] registry impls (consul/etcd/zookeeper/apollo) use non-thread-safe HashMap for watcherInstanceRegisterMap shared by caller + async watcher [shenyu]

Aias00 opened a new issue, #6835:
URL: https://github.com/apache/shenyu/issues/6835

   ## Description
   All four `shenyu-registry` instance-register implementations (consul/etcd/zookeeper/apollo) store the cached instance list (`watcherInstanceRegisterMap`) in a plain `java.util.HashMap`. This map is written by an async watcher/callback thread (Consul scheduled executor, etcd `Watch.listener`, Curator `CuratorWatcher`, Apollo `ConfigChangeListener`) while concurrently read and written by the caller thread in `selectInstances` (`containsKey`/`get`/`put`). The Zookeeper impl also races `nodeDataMap` between `persistInstance` (caller) and the `ConnectionState.RECONNECTED` listener; Apollo additionally mutates a local `HashMap childrenList` from the config thread. The Nacos impl already uses `ConcurrentHashMap`/`ConcurrentMap`.
   
   ## Location
   - `shenyu-registry/shenyu-registry-consul/src/main/java/org/apache/shenyu/registry/consul/ConsulInstanceRegisterRepository.java:76,90,92,160-196` (also `consulIndexes`:76, `watchSelectKeySet`:92)
   - `shenyu-registry/shenyu-registry-etcd/.../EtcdInstanceRegisterRepository.java:60,98,118-121`
   - `shenyu-registry/shenyu-registry-zookeeper/.../ZookeeperInstanceRegisterRepository.java:67,71,100,122,145-167`
   - `shenyu-registry/shenyu-registry-apollo/.../ApolloInstanceRegisterRepository.java:65,128-163`
   
   ## Impact
   Under normal multi-path operation, concurrent access corrupts the HashMap, loses instance updates (watcher misses instances or serves stale lists), produces inconsistent discovery state, or causes infinite-loop/CME-style hangs on the `selectInstances` path → wrong/missing upstream routing.
   
   ## Suggested fix
   Replace all `new HashMap<>()` / `new HashSet<>()` field declarations with `Maps.newConcurrentMap()` / `ConcurrentHashMap.newKeySet()` (as the Nacos impl already does), or guard all access with a single `synchronized` lock. For the Apollo local `childrenList`, use `ConcurrentHashMap` or copy before passing to the listener.
   
   ## Related existing
   Distinct from SYNC-8 (#6783, `ConsulSyncDataService` HashMap) — that covers `shenyu-sync-data-center/shenyu-sync-data-consul` (gateway-side sync service), not `shenyu-registry-consul` (instance register repository). The Nacos registry is already safe.
   


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

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


Re: [I] [BUG] registry impls (consul/etcd/zookeeper/apollo) use non-thread-safe HashMap for watcherInstanceRegisterMap shared by caller + async watcher [shenyu]

Posted by "hengyuss (via GitHub)" <gi...@apache.org>.
hengyuss commented on issue #6835:
URL: https://github.com/apache/shenyu/issues/6835#issuecomment-5436030274

   /assign


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

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


Re: [I] [BUG] registry impls (consul/etcd/zookeeper/apollo) use non-thread-safe HashMap for watcherInstanceRegisterMap shared by caller + async watcher [shenyu]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #6835:
URL: https://github.com/apache/shenyu/issues/6835#issuecomment-5174029984

   👋 Hello @Aias00
   
   A new issue has been opened by @Aias00:
   - **Title**: [BUG] registry impls (consul/etcd/zookeeper/apollo) use non-thread-safe HashMap for watcherInstanceRegisterMap shared by caller + async watcher
   - **Link**: https://github.com/apache/shenyu/issues/6835
   
   Please review when you have time. Thank you! 🙏


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

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


Re: [I] [BUG] registry impls (consul/etcd/zookeeper/apollo) use non-thread-safe HashMap for watcherInstanceRegisterMap shared by caller + async watcher [shenyu]

Posted by "Aias00 (via GitHub)" <gi...@apache.org>.
Aias00 closed issue #6835: [BUG] registry impls (consul/etcd/zookeeper/apollo) use non-thread-safe HashMap for watcherInstanceRegisterMap shared by caller + async watcher
URL: https://github.com/apache/shenyu/issues/6835


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

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