xiaobaicai66695 opened a new issue, #16548:
URL: https://github.com/apache/dubbo/issues/16548

   ## Pre-check
   
   - [x] All content in this report is in English.
   
   ## Search before asking
   
   I searched `apache/dubbo` issues for `AppScriptStateRouter DELETED`, `script 
router rule delete`, and `No provider available script routing`. I found no 
issue covering the rule-deletion failure. 
[#16545](https://github.com/apache/dubbo/issues/16545) covers a separate 
cross-service router-chain bug; it is not required to reproduce this failure.
   
   ## Apache Dubbo Component
   
   Java SDK (`apache/dubbo`), `dubbo-cluster`, application-level script routing 
(`AppScriptStateRouter`).
   
   ## Dubbo Version
   
   - Apache Dubbo Java SDK **3.3.6** from Maven Central. The error also 
reproduces in the unmodified 3.3 branch at commit 
[843b98b](https://github.com/apache/dubbo/commit/843b98b3a1c70134e965ab04efc2de668238e0b2)
 using a targeted regression test.
   - Amazon Corretto JDK **1.8.0_442** (bundled Nashorn JavaScript engine), 
Windows 11 build 26200.
   - Nacos **2.5.2** standalone as the configuration center, mapped to 
`127.0.0.1:18848` (HTTP) and `127.0.0.1:19848` (gRPC).
   - Curator `TestingServer` **5.9.0** as the ZooKeeper registry at 
`127.0.0.1:23281`.
   - Two provider JVMs and one consumer JVM. No Spring application is needed.
   
   ## Steps to reproduce this issue
   
   1. Start Nacos and ZooKeeper. The local Nacos command was `docker run -d 
--name codex-dubbo-script-repro-nacos -e MODE=standalone -e 
NACOS_AUTH_ENABLE=false -p 127.0.0.1:18848:8848 -p 127.0.0.1:19848:9848 
nacos/nacos-server:v2.5.2`. Start two separate provider JVMs for the same 
`OrderProbeService`: `order-v1` at `127.0.0.1:23981` and `order-v2` at 
`127.0.0.1:23982`. Both use provider application name 
`route-chain-repro-order`. The method `String instance()` returns the instance 
ID.
   2. Publish the following YAML to Nacos group `dubbo`, Data ID 
`route-chain-repro-order.script-router`:
   
      ```yaml
      configVersion: v3.0
      scope: application
      key: route-chain-repro-order
      runtime: true
      enabled: true
      force: true
      type: javascript
      script: |
        (function route(invokers, invocation) {
            var result = new java.util.ArrayList();
            for (var i = 0; i < invokers.size(); i++) {
                if (invokers.get(i).getUrl().getPort() == 23982) {
                    result.add(invokers.get(i));
                }
            }
            return result;
        })(invokers, invocation);
      ```
   
   3. Start a single-reference consumer JVM using the same ZooKeeper registry 
and Nacos config center. Set `roundrobin` load balancing and `retries=0` on the 
Order reference. Invoke `instance()` five times; all five calls return 
`order-v2`.
   4. In Nacos, delete that Data ID with 
`ConfigService.removeConfig("route-chain-repro-order.script-router", "dubbo")`. 
Confirm the Nacos HTTP config endpoint returns **404**, wait five seconds for 
the config notification, then invoke `instance()` five more times on the same 
consumer reference.
   5. Republish the same YAML, wait five seconds, and invoke `instance()` five 
more times.
   
   The rule lifecycle in the reproducer is:
   
   ```java
   observe("BEFORE_DELETE", order, 5);
   config.removeConfig("route-chain-repro-order.script-router", "dubbo");
   waitUntilNacosGetReturns404();
   Thread.sleep(5000);
   observe("AFTER_DELETE", order, 5);
   config.publishConfig("route-chain-repro-order.script-router", "dubbo", rule);
   Thread.sleep(5000);
   observe("AFTER_RESTORE", order, 5);
   ```
   
   Each `observe` call counts the returned provider IDs and caught exceptions. 
Providers remain registered and healthy throughout. The same failure was also 
confirmed with a second `UserProbeService` reference in the consumer when using 
the independent router-chain fix proposed in [PR 
#16546](https://github.com/apache/dubbo/pull/16546).
   
   ## What you expected to happen
   
   Deleting the script rule should disable script filtering. While the rule is 
absent, both healthy Order providers should remain available for normal load 
balancing. Republishing the rule should restore v2-only routing. No RPC should 
fail solely because the rule was deleted.
   
   ## What actually happened
   
   The original Dubbo **3.3.6 single-reference** run returned:
   
   ```text
   BEFORE_DELETE={order-v2=5}
   NACOS_HTTP_AFTER_DELETE=404
   AFTER_DELETE={ERROR:RpcException=5}
   AFTER_RESTORE={order-v2=5}
   ```
   
   The two-reference run with the separate 
[#16545](https://github.com/apache/dubbo/issues/16545) chain fix had the same 
5/5 errors after deletion. The consumer log contains 
`java.lang.NullPointerException` at 
`AppScriptStateRouter.doRoute(AppScriptStateRouter.java:69)`, followed by 
`Failed to execute router` and `No provider available`. The failure happens in 
a single-reference consumer without the #16545 fix, so the chain fix is not its 
cause.
   
   ## Anything else
   
   The `DELETED` handler in 
[`AppScriptStateRouter.process`](https://github.com/apache/dubbo/blob/dubbo-3.3.6/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/config/AppScriptStateRouter.java)
 sets `scriptRule = null` but leaves the compiled `scriptRouter` non-null. On 
the next call, `doRoute` passes the `scriptRouter == null` check and 
dereferences `scriptRule.isValid()`. `DynamicDirectory.doList` catches the 
routing exception and returns an empty candidate list, so the cluster reports 
that no provider is available even though both providers are healthy.
   
   A fix should publish the rule and compiled router together as one state, and 
clear both on deletion. This also avoids observing mismatched state when config 
updates race with invocation routing. A regression test can assert routing 
before deletion, pass-through after deletion, and restored script routing after 
republishing.
   
   I tested that approach locally against real RPCs using the original Dubbo 
3.3.6 router factory and, separately, the #16545 router-chain fix. In both 
setups, after deletion the five calls reached both providers (`order-v1=2, 
order-v2=3`) with zero errors; after republishing, all five reached `order-v2`. 
The targeted regression test initially failed with the same NPE on unmodified 
3.3 source and passed after the fix.
   
   ## Do you have a (mini) reproduction demo?
   
   Yes. The local reproducer uses separate provider and consumer JVMs, an 
embedded ZooKeeper server, Nacos 2.5.2, the YAML above, and the lifecycle code 
shown above. The provider/consumer setup is the same as the complete runnable 
source in [#16545](https://github.com/apache/dubbo/issues/16545); the 
additional dynamic deletion sequence is shown here. The fix includes a 
regression test in `AppScriptStateRouterTest`.
   
   ## Are you willing to submit a pull request to fix on your own?
   
   Yes. The fix and regression test are prepared locally.
   
   ## Code of Conduct
   
   I agree to follow the project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct).
   
   


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