Fix startup NPE when a weakly dependent registry is unavailable (check=false)#16356
Open
AryamannSingh7 wants to merge 1 commit into
Open
Fix startup NPE when a weakly dependent registry is unavailable (check=false)#16356AryamannSingh7 wants to merge 1 commit into
AryamannSingh7 wants to merge 1 commit into
Conversation
…check=false When a registry cannot be created and check=false (e.g. a weakly dependent ZooKeeper is down at startup), AbstractRegistryFactory returns a null registry which RegistryFactoryWrapper still wraps in a ListenerRegistryWrapper. The wrapper already guards register/unregister/subscribe against a null delegate, but getUrl/isAvailable/destroy/unsubscribe/isServiceDiscovery/lookup did not, and RegistryDirectory#subscribe dereferences registry.getUrl() unconditionally to build a metrics label (added in apache#12582), causing an NPE since 3.2.5. Complete the null-safety in ListenerRegistryWrapper and guard the metrics label computation in RegistryDirectory#subscribe so a service can still start when a non-critical registry is unavailable. Fixes apache#16178
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16356 +/- ##
============================================
+ Coverage 60.81% 60.85% +0.03%
- Complexity 30 11762 +11732
============================================
Files 1953 1953
Lines 89213 89217 +4
Branches 13460 13460
============================================
+ Hits 54254 54290 +36
+ Misses 29374 29349 -25
+ Partials 5585 5578 -7
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?
Fixes #16178.
When a service subscribes to multiple registries and one of them is weakly dependent (
check="false") and unavailable at startup, the application fails to start with:This is a regression: Dubbo
3.2.0–3.2.4start successfully,3.2.5+ fail (also reproduced on3.3.x).Root cause
Under
check=false, when a registry cannot be created (the registry is down),AbstractRegistryFactory#getRegistryswallows the exception and returnsnull.RegistryFactoryWrapperstill wraps thisnullinto aListenerRegistryWrapper, so a null delegate is an expected state —ListenerRegistryWrapperalready guardsregister/unregister/subscribewithif (registry != null).However:
getUrl/isAvailable/destroy/unsubscribe/isServiceDiscovery/lookupwere not guarded.RegistryDirectory#subscribecomputes a metrics cluster name viaregistry.getUrl().getParameter(...)unconditionally. That line was introduced in Support multi registries metrics key #12582 (released in3.2.5), which is exactly why the NPE appears from3.2.5onward.What changed
ListenerRegistryWrapper— complete the existing null-safety:getUrlreturnsnull,isAvailable/isServiceDiscoveryreturnfalse,destroy/unsubscribebecome no-ops, andlookupreturns an empty list when the delegate registry isnull.RegistryDirectory#subscribe— guard the metrics cluster-name computation against anullregistry URL (no cluster name is reported when the registry is unavailable).RegistryEvent#toSubscribeEventalready tolerates anullname.Verification
Added
ListenerRegistryWrapperTest#testNullRegistryIsTolerated, which reproduces the exact NPE without the fix and passes with it.:dubbo-registry-apitests andspotless:checkpass locally (JDK 21).Checklist