Skip to content

Fix application script routing after rule deletion - #16549

Open
xiaobaicai66695 wants to merge 2 commits into
apache:3.3from
xiaobaicai66695:codex/fix-app-script-router-delete
Open

xiaobaicai66695 wants to merge 2 commits into
apache:3.3from
xiaobaicai66695:codex/fix-app-script-router-delete

Conversation

@xiaobaicai66695

Copy link
Copy Markdown

What does this PR do?

Fixes #16548.

  • Store the script rule and compiled script router in one immutable state and publish it through a single volatile reference.
  • Clear that state when a configuration DELETED event arrives, so routing passes through to the healthy provider candidates.
  • Add a regression test for rule addition, deletion, and republishing.

Why?

In 3.3.6, AppScriptStateRouter.process(DELETED) clears scriptRule but leaves scriptRouter non-null. The next invocation passes the null-router guard and dereferences scriptRule.isValid(). DynamicDirectory catches the exception and returns an empty invoker list, causing No provider available even when providers are healthy. Publishing the rule and compiled router together also prevents an invocation from observing values from different configuration revisions.

This bug reproduces with a single service reference on unmodified 3.3.6. It is independent of the cross-service chain issue in #16545 and #16546.

How was this tested?

  • The new AppScriptStateRouterTest case fails with a NullPointerException at doRoute on unmodified 3.3 source, then passes with this change.
  • ./mvnw -pl dubbo-cluster -Dtest=AppScriptStateRouterTest -Dsurefire.failIfNoSpecifiedTests=false test: 2 tests, 0 failures, 0 errors.
  • Local real-RPC E2E with Nacos 2.5.2, an embedded ZooKeeper registry, two Order provider JVMs, and one consumer JVM:
    • With the original 3.3.6 router factory and one reference: before deletion v2=5; after Nacos returned 404, v1=2/v2=3; after republishing v2=5.
    • With the separate per-service router-factory fix and two references: the same sequence and counts.
    • No router NPE or provider-unavailable error after deletion.

No production cluster changes are included in this PR.

@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.92%. Comparing base (843b98b) to head (5156fdc).

Files with missing lines Patch % Lines
...ter/router/script/config/AppScriptStateRouter.java 69.23% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16549      +/-   ##
============================================
+ Coverage     60.90%   60.92%   +0.01%     
- Complexity       15       30      +15     
============================================
  Files          1953     1953              
  Lines         89280    89286       +6     
  Branches      13476    13478       +2     
============================================
+ Hits          54376    54394      +18     
+ Misses        29323    29311      -12     
  Partials       5581     5581              
Flag Coverage Δ
integration-tests-java21 32.08% <7.69%> (+<0.01%) ⬆️
integration-tests-java8 32.21% <7.69%> (+0.06%) ⬆️
samples-tests-java21 32.11% <7.69%> (-0.02%) ⬇️
samples-tests-java8 29.80% <7.69%> (+0.02%) ⬆️
unit-tests-java11 59.19% <69.23%> (+0.08%) ⬆️
unit-tests-java17 58.61% <7.69%> (+0.01%) ⬆️
unit-tests-java21 58.61% <7.69%> (-0.03%) ⬇️
unit-tests-java25 58.55% <7.69%> (-0.05%) ⬇️
unit-tests-java8 59.16% <69.23%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@EarthChen EarthChen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Confirmed the bug: after a rule is deleted, scriptRule is null but scriptRouter stays non-null, so doRoute hits an NPE on scriptRule.isValid(). Merging rule and router into one immutable RouterState published through a volatile field fixes it and removes the null-check/dereference race. A failed ScriptStateRouter construction now keeps the old state.

Verified locally: AppScriptStateRouterTest passes with this PR, and fails with an NPE in doRoute when the main class is reverted to 3.3.

This branch has not been deployed

No deployments
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] Deleting an application script routing rule makes healthy providers unavailable

3 participants