Skip to content

fix: allow metadata service export when application deployer is PENDING#16249

Open
daguimu wants to merge 1 commit intoapache:3.3from
daguimu:fix/programmatic-service-metadata-14859
Open

fix: allow metadata service export when application deployer is PENDING#16249
daguimu wants to merge 1 commit intoapache:3.3from
daguimu:fix/programmatic-service-metadata-14859

Conversation

@daguimu
Copy link
Copy Markdown

@daguimu daguimu commented Apr 29, 2026

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 the PENDING state. In that state DefaultApplicationDeployer#doExportMetadataService returns immediately, so the metadata service is never exported and the ApplicationDeployListener#onModuleStarted listeners that drive instance-level registration are never fired.

Root Cause

private void doExportMetadataService() {
    if (!isStarting() && !isStarted() && !isCompletion()) {
        return;
    }
    ...
}

The guard is an inclusive whitelist of three lifecycle states. Any other state — including the PENDING state of a freshly-created deployer — is treated as "skip". For programmatic export this happens before start() 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, COMPLETION all proceed.

if (isStopping() || isStopped() || isFailed()) {
    return;
}

Tests Added

Change point Test
Metadata export is now allowed in PENDING state exportMetadataServiceShouldFireListenersWhenDeployerIsPending() — registers an ApplicationDeployListener, asserts the deployer is in PENDING, calls exportMetadataService(), asserts onModuleStarted fired exactly once

mvn -am -pl dubbo-config/dubbo-config-api test -Dtest=DefaultApplicationDeployerTest -Dsurefire.failIfNoSpecifiedTests=false — 3/3 tests pass.

Impact

Fixes #14859

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-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.77%. Comparing base (ca72307) to head (576363d).
⚠️ Report is 1 commits behind head on 3.3.

Files with missing lines Patch % Lines
...ubbo/config/deploy/DefaultApplicationDeployer.java 0.00% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
integration-tests-java21 32.04% <0.00%> (-0.08%) ⬇️
integration-tests-java8 32.12% <0.00%> (-0.12%) ⬇️
samples-tests-java21 32.13% <0.00%> (-0.07%) ⬇️
samples-tests-java8 29.79% <0.00%> (+0.05%) ⬆️
unit-tests-java11 59.02% <0.00%> (-0.01%) ⬇️
unit-tests-java17 58.51% <0.00%> (+<0.01%) ⬆️
unit-tests-java21 58.51% <0.00%> (+0.01%) ⬆️
unit-tests-java25 58.46% <0.00%> (ø)
unit-tests-java8 59.00% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] When registering services programmatically in Dubbo 3.3.x, the instance - level service registration is invalid.

2 participants