Repository navigation
fix: remove faulty size guard so REFRESH cleans up stale plugin/auth/meta config nodes - #7014
Conversation
…meta config nodes (#6874) The REFRESH/MYSELF branch of AbstractNodeDataChangedListener#onCommonChanged only removed stale entries when the old set strictly outnumbered the new one, so refreshes with equal or larger cardinality (e.g. old=[A,B,C,D] -> new=[C,D,E,F]) left orphaned config nodes in nacos/apollo/polaris. Removed the size guard and fixed the stale-entry delConfig call to use the correct namespaced key.
There was a problem hiding this comment.
Pull request overview
This PR fixes stale config-node cleanup during namespace-wide REFRESH/MYSELF sync events in AbstractNodeDataChangedListener#onCommonChanged, ensuring removed plugin/app-auth/metadata entries are correctly deleted from config centers even when the refreshed set’s cardinality stays the same (or increases). This aligns admin-side publish/delete behavior with how gateway-side watchers consume {prefix}.list and {prefix}{entryKey} nodes.
Changes:
- Remove the incorrect
old.size() > new.size()guard so stale-entry diffing/deletion always runs forREFRESH/MYSELF. - Fix stale-entry deletion to pass the fully qualified dataId (
configKeyPrefix + staleName) intodelConfig. - Add a regression test covering equal-cardinality replacement (e.g.,
A,B,C,D -> C,D,E,F) and asserting stale entries are deleted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| shenyu-admin-listener/shenyu-admin-listener-api/src/main/java/org/apache/shenyu/admin/listener/AbstractNodeDataChangedListener.java | Always computes/removes stale keys on REFRESH/MYSELF and deletes correctly namespaced per-entry nodes. |
| shenyu-admin-listener/shenyu-admin-listener-api/src/test/java/org/apache/shenyu/admin/listener/AbstractNodeDataChangedListenerTest.java | Adds regression coverage for equal-cardinality REFRESH replacing membership and verifies stale node deletion. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Aias00
left a comment
There was a problem hiding this comment.
Summary
Fixes #6874 — AbstractNodeDataChangedListener.onCommonChanged skipped stale-entry cleanup on REFRESH and deleted config under the wrong key.
Changes
- if (Objects.nonNull(configDataNames) && configDataNames.size() > changedList.size()) {
+ if (Objects.nonNull(configDataNames)) {
configDataNames.removeAll(changeNames);
- configDataNames.forEach(this::delConfig);
+ configDataNames.forEach(staleName -> delConfig(configKeyPrefix + staleName));
}- Removed the faulty size guard
configDataNames.size() > changedList.size(). It prevented deletion of stale entries whenever the existing config count was not strictly greater than the incoming change count. Example: existing[A,B,C,D]+LIST=[A,B,C,D], thenREFRESHwith[C,D,E,F]— old guard4 > 4is false, so staleA,Bwere never deleted. Removing the guard ensures every name left afterremoveAll(changeNames)(i.e. genuinely stale) is cleaned. - Fixed the delete key from
delConfig(staleName)todelConfig(configKeyPrefix + staleName).getConfigDataNamesreturns bare names fromLIST_STR, so the prefix must be re-applied — matching thepublishConfig(configKeyPrefix + ...)/delConfig(configKeyPrefix + ...)convention used elsewhere (e.g. L126). The old code deleted a key without the prefix (wrong / non-existent) and left the real stale entry behind.
Verification
delConfig(final String dataId)(L320) takes the full config key;getConfigDataNames(L346) returns bare names — prependingconfigKeyPrefixis required and correct.- Test
testOnPluginChangedRefreshWithEqualCardinalityRemovesStaleEntriesreproduces the equal-cardinality case and assertsA/Bare deleted viawasDeleted(configKeyPrefix + "A"/"B"). - Existing refresh test
testOnSelectorChangedRefreshReplacesPluginSelectorIdsremains valid.
Conclusion
Two precise, well-tested correctness fixes for REFRESH stale-config cleanup. Approved.
…meta config nodes (apache#6874) (apache#7014) The REFRESH/MYSELF branch of AbstractNodeDataChangedListener#onCommonChanged only removed stale entries when the old set strictly outnumbered the new one, so refreshes with equal or larger cardinality (e.g. old=[A,B,C,D] -> new=[C,D,E,F]) left orphaned config nodes in nacos/apollo/polaris. Removed the size guard and fixed the stale-entry delConfig call to use the correct namespaced key. Co-authored-by: Luke Haochao Zhuang <[email protected]> Co-authored-by: aias00 <[email protected]>
What is the purpose of the change
Fixes #6874.
In
AbstractNodeDataChangedListener#onCommonChanged, the REFRESH/MYSELF branch only removed stale plugin/app-auth/metadata config entries when the old set strictly outnumbered the new one (configDataNames.size() > changedList.size()). When a REFRESH replaced the set with equal or larger cardinality but different members (e.g. old=[A,B,C,D], new=[C,D,E,F]), the guard was false, so stale entries A and B were never removed from nacos/apollo/polaris config centers — only orphaned per-entry config nodes remained while the LIST node was overwritten.This path is reached by
syncAllByNamespaceId(REFRESH, ns)fromNamespacePluginControllerandConfigsExportImportController, which publish PLUGIN/AUTH/META REFRESH events spanning a whole namespace. For app-auth this is security-adjacent, since a deleted app key's config node could linger and be served to gateways that read it before the list update propagates.Changes
removeAll) always runs.delConfigcall to use the correctly namespaced key (configKeyPrefix + name) instead of the bare entry name, which was also silently preventing cleanup even when the guard passed.Does this PR introduce a user-facing change?
No.