Sean-Walker0 opened a new pull request, #7282: URL: https://github.com/apache/shenyu/pull/7282
<!-- Describe your PR here; e.g. Fixes #issueNo --> `SofaPluginDataHandler#handlerSelector` compares the freshly parsed `SofaUpstream` against `ApplicationConfigCache#getUpstream(selectorData.getId())`. But the upstream map is keyed by the **full reference cache key** (selector id, metadata path, protocol and registry hash \u2014 see `SofaProxyService`, which calls `putUpstream(generateUpstreamCacheKey(...))`), so a lookup with the bare selector id **never hits** and the old config is always `null`. The change detection therefore degenerates to "new vs null": | selector event | old behavior | intended behavior | |---|---|---| | handle **unchanged** (re-save, unrelated field edit) | `!equals(new, null)` = true \u2192 **invalidates**: live references destroyed \u2192 transient sofa call failures + registry reconnection churn on every admin save | no-op | | handle **removed** | `!equals(null, null)` = false \u2192 **never invalidates**: references built from the removed registry keep serving until restart | invalidate | | handle **changed** | invalidates (by accident) | invalidate | Both failure directions are proven by the new tests, which fail on master (red) and pass with this change (green). <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [x] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [x] You submit test cases (unit or integration tests) that back your changes. - [x] Your local test passed `./mvnw test -pl shenyu-plugin/shenyu-plugin-rpc/shenyu-plugin-sofa -am` and `./mvnw checkstyle:check -pl shenyu-plugin/shenyu-plugin-rpc/shenyu-plugin-sofa` (module-scoped; full build left to CI). ### Modifications - Track the last seen `SofaUpstream` per selector id in a `SELECTOR_UPSTREAM_MAP` inside the handler and compare against that account instead of the never-matching map lookup. - Keep the account in sync: record/update on change, remove on handle removal, remove per selector in `removeSelector`, clear in `removePlugin` (which already invalidates all). ### Verifying this change - New tests in `SofaPluginDataHandlerTest` seed the real reference cache and assert: unchanged handle does **not** invalidate, changed handle invalidates, removed handle invalidates. The first two plus the removal case fail on current master. - Full `shenyu-plugin-sofa` module suite passed (including the existing `ApplicationConfigCacheTest` segment-matching tests from #7217); checkstyle passed. ### Notes - Found while auditing the sofa reference cache for #7217; no issue was filed for this defect \u2014 happy to open one retroactively if maintainers prefer. - After this change `ApplicationConfigCache#getUpstream` has no in-repo caller left (it was the only one); it could be removed in a follow-up. -- 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]
