Sean-Walker0 opened a new pull request, #7376:
URL: https://github.com/apache/shenyu/pull/7376

   <!-- Describe your PR here; e.g. Fixes #issueNo -->
   Found by code audit (no existing issue — happy to file one if maintainers 
prefer).
   
   `ApplicationConfigCache` stores the primary sofa reference under the **bare 
metadata path** (`cache.put(metaData.getPath(), reference)`, `:270`). But 
`SofaMetaDataHandler#remove()` — and the changed-handle branch of `handle()` — 
only call `invalidateWithMetadataPath`, which delegates to 
`invalidateByWholeSegment`: a scanner matching keys that contain the 
`KEY_SEPARATOR`-wrapped token `"|" + path + "|"`. A bare-path key can never 
contain that token, so **the primary cache entry always survives removal**:
   
   - re-registering metadata under the same path with a different 
`serviceName`/`rpcExt` reuses the stale `ConsumerConfig` — 
`SofaProxyService#genericInvoker` keeps invoking the **old** interface;
   - the cache's `removalListener` — which exists precisely to null out 
`consumerBootstrap` ("it will get NULL when reinitializing and cause a NULL 
pointer problem") — never fires for these entries.
   
   The dubbo sibling is the intent proof: 
`ApacheDubboMetaDataHandler#invalidateReference` calls **both** 
`invalidate(metaData.getPath())` (exact bare-path key) and the segment-based 
variant.
   
   <!--
   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-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa -am and 
./mvnw checkstyle:check -pl 
shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-sofa` 
(module-scoped; full build left to CI).
   
   ### Modifications
   
   - Add `ApplicationConfigCache.getInstance().invalidate(metaData.getPath())` 
before the segment-based invalidation in both `remove()` and the changed-handle 
branch of `handle()` — mirroring the dubbo sibling's two-pronged 
`invalidateReference`.
   
   ### Verifying this change
   
   - New `removeShouldInvalidateThePlainPathCacheEntry` (reflection-seeded 
cache, following the file's existing `handleNullMetadataFieldsTest` pattern) 
puts a mocked `ConsumerConfig` under a bare path, calls `remove()`, and asserts 
the entry is gone. It fails on current master (`expected: <null> but was: <Mock 
for ConsumerConfig...>`) and passes with this change.
   - Full `shenyu-plugin-sofa` module suite green (185 test classes across the 
reactor); checkstyle green.
   
   ### Notes
   
   - Behavior change: removing or re-configuring sofa metadata now drops the 
cached reference, so re-registration rebuilds it instead of silently invoking 
the old interface.
   - Orthogonal to open PRs: no open PR touches the sofa handler or the sofa 
`ApplicationConfigCache` (the identically-named **tars** cache is touched by 
#7159/#7100 — different module; verified by full-path matching against all 200 
open PRs' file lists).


-- 
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]

Reply via email to