Lubaoshuai opened a new pull request, #16462:
URL: https://github.com/apache/dubbo/pull/16462

   ## What is the purpose of the change
   
   Concurrent admin-protocol subscriptions can leak non-daemon scheduler 
threads in NacosRegistry.
   
   `scheduleServiceNamesLookup` performs an unsynchronized check-then-act on 
the `scheduledExecutorService` field: two concurrent `subscribe` calls with 
`protocol=admin` (e.g. multiple Dubbo Admin/ops clients) can both observe 
`null` and each create their own single-thread scheduled executor. 
`shutdownServiceNamesLookup()` only shuts down the last assigned reference, so 
every racing duplicate executor keeps polling `getAllServiceNames()` forever. 
The default thread factory also creates non-daemon threads, so the leaked 
schedulers block JVM exit.
   
   ## Brief changelog
   
   - Create the scheduler under double-checked locking and publish the volatile 
field only after the periodic task has been scheduled on the local reference.
   - Use a named daemon thread factory (`Dubbo-Nacos-Registry-Scheduler`) so 
leaks, if any, are identifiable in thread dumps and cannot block shutdown.
   
   ## Verifying this change
   
   - Added 
`NacosRegistryTest.testConcurrentAdminSubscribeCreatesSingleDaemonScheduler`: 8 
concurrent admin-protocol subscribes against a mock NamingService assert 
exactly one scheduler thread exists, it is a daemon, and it terminates after 
`unsubscribe`.
   - `mvn -pl dubbo-registry/dubbo-registry-nacos -am test 
-Dtest=NacosRegistryTest` passes (6/6).
   
   Fixes #15886
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to