fix: allow metadata service export when application deployer is PENDING#16249
Open
daguimu wants to merge 1 commit intoapache:3.3from
Open
fix: allow metadata service export when application deployer is PENDING#16249daguimu wants to merge 1 commit intoapache:3.3from
daguimu wants to merge 1 commit intoapache:3.3from
Conversation
DefaultApplicationDeployer#doExportMetadataService used to bail out when the deployer was not in STARTING/STARTED/COMPLETION state. That blocked programmatic ServiceConfig.export() invocations made before the application has been started, because the deployer is still in PENDING state at that point and the metadata service was therefore silently skipped — instance-level registration would then run without metadata. Invert the guard so we only skip when the deployer is shutting down or has failed (STOPPING / STOPPED / FAILED). PENDING / INIT / STARTING / STARTED / COMPLETION all remain valid states for triggering the export. Add DefaultApplicationDeployerTest#exportMetadataServiceShouldFireListenersWhenDeployerIsPending which registers a deploy listener and asserts onModuleStarted is invoked exactly once after exportMetadataService() runs against a freshly-created (PENDING) deployer. Fixes apache#14859
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16249 +/- ##
============================================
- Coverage 60.78% 60.77% -0.02%
+ Complexity 11768 11757 -11
============================================
Files 1953 1953
Lines 89186 89186
Branches 13454 13454
============================================
- Hits 54213 54201 -12
- Misses 29400 29401 +1
- Partials 5573 5584 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 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.
Problem
When a service is exported programmatically via
ServiceConfig.export()before the application context has been started (typical of XML-driven Dubbo wiring without<dubbo:service/>entries), the deployer is still in thePENDINGstate. In that stateDefaultApplicationDeployer#doExportMetadataServicereturns immediately, so the metadata service is never exported and theApplicationDeployListener#onModuleStartedlisteners that drive instance-level registration are never fired.Root Cause
The guard is an inclusive whitelist of three lifecycle states. Any other state — including the
PENDINGstate of a freshly-created deployer — is treated as "skip". For programmatic export this happens beforestart()is invoked, so the metadata service is silently skipped.Fix
Replace the whitelist with an exclusion of the only states in which we genuinely cannot run a metadata export: shutting-down (
STOPPING/STOPPED) and failed (FAILED).PENDING,INIT,STARTING,STARTED,COMPLETIONall proceed.Tests Added
PENDINGstateexportMetadataServiceShouldFireListenersWhenDeployerIsPending()— registers anApplicationDeployListener, asserts the deployer is inPENDING, callsexportMetadataService(), assertsonModuleStartedfired exactly oncemvn -am -pl dubbo-config/dubbo-config-api test -Dtest=DefaultApplicationDeployerTest -Dsurefire.failIfNoSpecifiedTests=false— 3/3 tests pass.Impact
ServiceConfig.export()made against aPENDINGdeployer now correctly exports the metadata service (this was already the behaviour in 3.2.x and is the regression that [Bug] When registering services programmatically in Dubbo 3.3.x, the instance - level service registration is invalid. #14859 reports).exportMetadataService()is invoked fromSTARTING/STARTED/COMPLETIONstill work (those states were already accepted by the old guard).STOPPING/STOPPED/FAILEDmirrors the original intent of the guard while no longer dropping thePENDINGcase.Fixes #14859