shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[BUG] Namespace-scoped empty REFRESH leaves stale state in node/path config centers

Open Aias00 opened this issue 1 month ago • 6 comments

Is there an existing issue for this?

  • [x] I searched open and closed issues.

Current Behavior

Admin emits a namespace-scoped full REFRESH with an empty list, but node/path-based config-center listeners ignore it. Stale entries remain in the config center instead of converging to the empty Admin state.

DataChangedEventDispatcher forwards the explicit namespace to three-argument listener methods. Their default implementations discard the namespace and invoke two-argument methods. The node listener returns immediately for empty lists; the path listener does no work and skips selector/rule subtree deletion when the list is empty.

Expected Behavior

A full refresh for a supplied namespace must reconcile the covered group to empty, without removing another namespace's data. Empty snapshots are meaningful and cannot rely on extracting namespace/plugin identity from a first row.

Steps To Reproduce

  1. Use Nacos/Apollo/Polaris or ZooKeeper/Etcd/Consul configuration synchronization.
  2. Publish selectors/rules in namespace namespace-a.
  3. Leave old config-center data behind after a missed/failed deletion or other stale-state condition while Admin's current group becomes empty.
  4. Run namespace synchronize or import followed by syncAllByNamespaceId(REFRESH, namespace-a).
  5. Observe an empty event carrying namespace-a, but no deletion/replacement of the old config-center entries.

An offline verifier seeded namespace-a and namespace-b in in-memory subclasses of the actual node/path listener bases, then invoked their actual three-argument methods. Current-source output:

PASS node empty REFRESH kept seeded APP_AUTH/PLUGIN/SELECTOR/RULE for namespace-a
PASS node nonempty REFRESH controls delete target namespace stale data and isolate other namespace
PASS path empty REFRESH kept seeded APP_AUTH/PLUGIN/SELECTOR/RULE for namespace-a
PASS path nonempty REFRESH controls delete target namespace stale selector/rule and isolate other namespace

Location And Scope

Verified groups: PLUGIN, SELECTOR, RULE, APP_AUTH. Verified shared listener families: node-based Nacos/Apollo/Polaris and path-based ZooKeeper/Etcd/Consul, whose concrete implementations inherit these methods.

This issue does not claim metadata/discovery/proxy-selector/AI-key behavior, nor HTTP/WebSocket behavior.

Impact

Severity: Medium. Confidence: high. Full synchronization cannot repair a config center whose last entries became stale after a deletion. Gateways can continue loading old routing/configuration data until an explicit deletion or manual center cleanup succeeds. Normal incremental delete delivery is a separate path; this reproduction targets full-refresh recovery with empty current data.

Suggested Fix And Regression Coverage

Implement namespace-aware full-refresh reconciliation in the node/path abstractions. On empty refresh, use the supplied namespace to remove stale group entries or replace lists with empty state. For selectors/rules, identify stored plugin/group parents without relying on a first current row. Keep CREATE/UPDATE/DELETE semantics and cross-namespace isolation unchanged.

Test previously populated -> empty namespace full refresh for each covered group, and verify another namespace survives. Retain nonempty replacement and ordinary incremental delete controls.

Validation And Related Issues

Reviewed 2.7.2-SNAPSHOT master at 67596c1d228b62da75cd0a0ecb47d0ac5d995384. Isolated verification and leader recompilation/reproduction confirmed the shared listener behavior. Existing AbstractNodeDataChangedListenerTest,AbstractPathDataChangedListenerTest: 8 tests passed.

#6831 fixed nonempty node refresh union behavior. #6832 fixed nonempty multi-plugin path refresh clearing. This is the empty namespace-aware payload discarded before those replacement algorithms can run. #6662/#6663 concern HTTP gateway refresh; #7356 concerns WebSocket convergence. Those channels are outside this finding.

No real config-center deployment was started; proof uses current listener source and in-memory persistence implementations.

Aias00 avatar Oct 07 '26 03:10 Aias00

👋 Hello @yuluo-yx

A new issue has been opened by @Aias00:

  • Title: [BUG] Namespace-scoped empty REFRESH leaves stale state in node/path config centers
  • Link: https://github.com/apache/shenyu/issues/7457

Please review when you have time. Thank you! 🙏

github-actions[bot] avatar Oct 07 '26 03:10 github-actions[bot]

Hi I would like to work on this issue. If no one is already working on this one, I will raise a pr.

GarvSaxena avatar Oct 14 '26 16:10 GarvSaxena

Hi @GarvSaxena, following up on your assignment on October 15. More than a week has passed, and I could not find a PR for this issue in its timeline or your recent PRs.

Could you share your current progress, any blockers, and when you expect to open a PR? A draft PR is welcome if the work is still in progress. If you have already submitted one, please link it here. If you are no longer planning to work on this, please let us know so the issue can be made available to another contributor.

Aias00 avatar Oct 31 '26 03:10 Aias00

Hi @Aias00,

Sorry for the delay in getting back to you. I was occupied with some other commitments and couldn't make progress on this issue earlier.

I’ll be working on it and plan to raise a PR within the upcoming week.

Thank you for following up, and apologies again for the delay!

6. Hi @GarvSaxena, following up on your assignment on October 15. More than a week has passed, and I could not find a PR for this issue in its timeline or your recent PRs. Could you share your current progress, any blockers, and when you expect to open a PR? A draft PR is welcome if the work is still in progress. If you have already submitted one, please link it here. If you are no longer planning to work on this, please let us know so the issue can be made available to another contributor.

GarvSaxena avatar Nov 01 '26 12:11 GarvSaxena

While reviewing the node/path config-center listeners on master (9dd9a12fb), I found two related REFRESH problems. They are close to this issue's scope and touch the same code, so I'm adding them here instead of opening separate issues. @GarvSaxena, they may be worth covering in the same fix.

1. A non-empty REFRESH does not clean up groups that are absent from the payload.

  • Node centers (Nacos, Apollo): AbstractNodeDataChangedListener.onCommonMultiChanged groups the payload by plugin name. refreshChangedMapToList (L245-L255) only rewrites the <ns>.selector.<plugin>.list index, and deletes stale ids, for plugins that appear in the payload. The same applies to rules, proxy selectors and discovery upstreams.
  • Path centers (ZooKeeper, etcd): AbstractPathDataChangedListener.onSelectorChanged / onRuleChanged (L119-L128, L161-L170) call deletePathRecursive only for parent paths derived from the payload.

So if plugin B lost all its selectors while a DELETE was missed (for example, a publish failure swallowed by the catch (Exception e) in onCommonMultiChanged), a later "sync all" REFRESH that only contains plugin A leaves B's keys or nodes in place. Restarted gateways still load them. This is the non-empty counterpart of the empty-list case described above.

2. The path-center REFRESH deletes before it re-creates.

For each plugin in the payload, deletePathRecursive(/ns/shenyu/selector/<plugin>) (and the rule path) runs first, and createOrUpdate then writes the nodes one by one. On ZooKeeper and etcd gateways, every NODE_DELETED becomes unCacheSelectorData / unCacheRuleData. Between the recursive delete and the last re-create, gateways have no selectors or rules for that plugin, so requests can fall through as unmatched during a "sync all". The node-center implementation already upserts first and then deletes only the stale ids, which avoids this window.

A REFRESH implementation for path centers that works out the stale set (existing children minus payload ids) and upserts before deleting would address both points, together with the empty-snapshot case in this issue.

Aias00 avatar Nov 11 '26 09:11 Aias00

Thanks for digging into this - both points line up with the fix in #8452.

  1. Non-empty REFRESH and groups absent from the payload

Covered for namespace-scoped REFRESH:

Node centers: onSelectorChanged/onRuleChanged/onPluginChanged/onAppAuthChanged now take the event namespace and, on REFRESH, reconcile against the stored indexes (.plugin.list, .selector..list) instead of only the payload groups. Plugins/selectors/rules absent from a non-empty snapshot are removed, same code path as the empty snapshot. Plugins missing from the plugin snapshot also drop their selector/rule groups, so ordering can't hide descendants. Path centers: namespace REFRESH lists the existing children under //shenyu/selector and //shenyu/rule (new getChildren() on the path listener, implemented for ZK/etcd), then deletes everything not present in the payload. This includes plugin B when the snapshot only contains plugin A. One deliberate exception: a REFRESH without an explicit namespaceId stays payload-scoped. That's the path used by syncPluginData for a single plugin, and reconciling the whole group there would wipe the other plugins. So if the "sync all" event in the scenario doesn't carry a namespace, it needs to use the namespace-scoped overload — otherwise it still won't clean up B. Worth confirming which event path you're seeing.

  1. Delete-before-recreate in path centers

Also fixed. Path REFRESH no longer does recursive delete + recreate. It upserts the full payload first, then computes existing children - payload ids and deletes only the stale nodes. On ZK/etcd that means no interval where a plugin has zero selectors/rules, which is the same upsert-then-delete ordering the node listener uses.

Metadata, discovery upstream, proxy selector, and AI-key groups are still out of scope here, per the issue; the same treatment for proxy selector/discovery would be a separate change.

Tests cover empty snapshot, non-empty snapshot with a missing plugin, ordering independence, cross-namespace isolation, and the upsert-before-delete ordering.

GarvSaxena avatar Nov 11 '26 13:11 GarvSaxena