Sean-Walker0 opened a new pull request, #7217: URL: https://github.com/apache/shenyu/pull/7217
<!-- Describe your PR here; e.g. Fixes #issueNo --> Fixes #6798 `ApacheDubboConfigCache` and the sofa `ApplicationConfigCache` invalidate cached rpc references with a plain `key.contains(id)` check. The cache keys are composite strings that join selector id, rule id, metadata id/path, protocol, an md5 hex of the registry url, version and group, so an id that appears as a **substring of an unrelated segment** wrongly invalidates live references belonging to other routes: - numeric snowflake ids can occur inside the 32-char hex md5 registry hash segment; - one selector id can be a substring of another rule/selector id (e.g. `15123` inside `9151239`); - in sofa, one metadata path can be a prefix of another (e.g. `/sofa/find` inside `/sofa/findAll`). Each spurious invalidation runs the removal listener, which destroys the `ReferenceConfig`/`ConsumerConfig` of an unrelated, possibly in-flight route, causing transient generic-call failures that are very hard to attribute. <!-- 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-sofa,shenyu-plugin-apache-dubbo -am` and `./mvnw checkstyle:check` on both modules (module-scoped; full build left to CI). ### Modifications - Build the reference cache keys with a `|` separator (instead of `_`) and wrap them with the same separator at both ends, in both `ApacheDubboConfigCache#generateUpstreamCacheKey` and the sofa `ApplicationConfigCache#generateUpstreamCacheKey`. `|` never occurs inside ids, paths, protocols, md5 hashes, versions or groups. - `invalidateWithSelectorId` / `invalidateWithRuleId` / `invalidateWithMetadataId` / `invalidateWithMetadataPath` now match the id **wrapped in separators** (`|id|`), so only whole key segments hit; shared logic moved into `invalidateByWholeSegment`. - Keys built by the path-based flow (`namespace + ":" + path`) are untouched and are never matched, same as before. ### Verifying this change - New deterministic unit tests in both cache test classes: substring-collision ids must survive (old code fails these), correct keys must still be invalidated, first-segment keys (blank namespace) must match, path-prefix collision must not invalidate, path-based entries stay untouched. - `shenyu-plugin-apache-dubbo`: 20/20 tests passed; `shenyu-plugin-sofa`: 26/26 tests passed; checkstyle passed on both modules. ### Notes - The cache key **format changed** (`_`-joined to `|`-joined and wrapped). Both caches are in-memory only and rebuilt lazily after a restart, so no migration or compatibility concern. - Two adjacent pre-existing issues found while working on this, intentionally **not** changed here, worth follow-ups: 1. `SofaUpstream#setRegister` is a no-op: it assigns `this.register = register;` while the parameter is named `registry`, so the field is assigned to itself (production populates it via Gson reflection, which is why it went unnoticed). 2. `SofaPluginDataHandler` reads `ApplicationConfigCache#getUpstream(selectorData.getId())` while `UPSTREAM_CACHE_MAP` is keyed by the full reference cache key, so the lookup never hits. -- 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]
