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

   ## 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
   
   ```java
   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.
   
   ```java
   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
   
   - Programmatic `ServiceConfig.export()` made against a `PENDING` deployer 
now correctly exports the metadata service (this was already the behaviour in 
3.2.x and is the regression that #14859 reports).
   - Existing flows where `exportMetadataService()` is invoked from 
`STARTING`/`STARTED`/`COMPLETION` still work (those states were already 
accepted by the old guard).
   - The new exclusion of `STOPPING`/`STOPPED`/`FAILED` mirrors the original 
intent of the guard while no longer dropping the `PENDING` case.
   
   Fixes #14859


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