fix(registry-nacos): guard lazy scheduler creation in NacosRegistry with double-checked locking - #16462
Open
Lubaoshuai wants to merge 1 commit into
Open
fix(registry-nacos): guard lazy scheduler creation in NacosRegistry with double-checked locking#16462Lubaoshuai wants to merge 1 commit into
Lubaoshuai wants to merge 1 commit into
Conversation
…ith double-checked locking scheduleServiceNamesLookup performed an unsynchronized check-then-act on the scheduledExecutorService field. Concurrent admin-protocol subscribes could each create their own single-thread executor; only the last assigned reference is shut down in shutdownServiceNamesLookup, leaking non-daemon scheduler threads that keep polling Nacos forever and block JVM exit. Create the executor under double-checked locking, publish it after the task is scheduled, and use a named daemon thread factory. Fixes apache#15886
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16462 +/- ##
============================================
+ Coverage 60.91% 60.97% +0.05%
- Complexity 15 11774 +11759
============================================
Files 1953 1953
Lines 89271 89275 +4
Branches 13473 13474 +1
============================================
+ Hits 54383 54436 +53
+ Misses 29309 29256 -53
- Partials 5579 5583 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Concurrent admin-protocol subscriptions can leak non-daemon scheduler threads in NacosRegistry.
scheduleServiceNamesLookupperforms an unsynchronized check-then-act on thescheduledExecutorServicefield: two concurrentsubscribecalls withprotocol=admin(e.g. multiple Dubbo Admin/ops clients) can both observenulland each create their own single-thread scheduled executor.shutdownServiceNamesLookup()only shuts down the last assigned reference, so every racing duplicate executor keeps pollinggetAllServiceNames()forever. The default thread factory also creates non-daemon threads, so the leaked schedulers block JVM exit.Brief changelog
Dubbo-Nacos-Registry-Scheduler) so leaks, if any, are identifiable in thread dumps and cannot block shutdown.Verifying this change
NacosRegistryTest.testConcurrentAdminSubscribeCreatesSingleDaemonScheduler: 8 concurrent admin-protocol subscribes against a mock NamingService assert exactly one scheduler thread exists, it is a daemon, and it terminates afterunsubscribe.mvn -pl dubbo-registry/dubbo-registry-nacos -am test -Dtest=NacosRegistryTestpasses (6/6).Fixes #15886