QiuYucheng2003 opened a new issue, #37714:
URL: https://github.com/apache/shardingsphere/issues/37714

   ### Which version of ShardingSphere did you use? Master / Latest (Source 
code analysis)
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? 
ShardingSphere-Mode (Cluster Repository - Etcd)
   
   ### Expected behavior
   1. Instance Isolation: Multiple instances of EtcdRepository should run 
independently. Closing one instance should not affect the functionality of 
other active instances.
   
   2. Lifecycle Management: Thread pools should be bound to the instance 
lifecycle to ensure they can be properly garbage collected in containerized 
environments (e.g., Tomcat, Flink).
   
   ### Actual behavior
   1. Shared State Corruption: When close() is called on any single 
EtcdRepository instance, it shuts down the EVENT_LISTENER_EXECUTOR. Since this 
executor is static, it kills the event listeners for all other running 
instances, causing RejectedExecutionException.
   
   2. ClassLoader Leak: The private static final thread pool holds a strong 
reference to the class loader. In hot-deployment scenarios, this prevents the 
module from being unloaded, leading to OutOfMemoryError: Metaspace.
   
   ### Reason analyze 
   In org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository:
   1. Static Definition (Line 66):
   private static final ExecutorService EVENT_LISTENER_EXECUTOR = ...
   
   2. Instance Termination (Line 185):
   @Override
   public void close() {
       client.close();
       EVENT_LISTENER_EXECUTOR.shutdown(); // BUG: Shuts down the GLOBAL static 
executor
   }
   The instance-level close() method terminates the global static resource. 
This is a severe lifecycle mismatch (NT-Misuse).
   
   ### Steps to reproduce the behavior
   1. Initialize EtcdRepository Instance A.
   
   2. Initialize EtcdRepository Instance B.
   
   3. Call instanceA.close().
   
   4. Trigger a watch event on Instance B.
   
   5. Result: Instance B throws RejectedExecutionException because the shared 
static executor was terminated by Instance A.
   
   ### Example codes for reproduce this issue (such as a github link).
   
https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java#L66


-- 
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: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to