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

   <!-- Describe your PR here; e.g. Fixes #issueNo -->
   Found by code audit (no existing issue — happy to file one if maintainers 
prefer).
   
   `removeDiscovery` drops only the `discoveryServiceCache` entry and never 
clears the matching `dataChangedEventListenerCache` entry that 
`createProxySelector` registers (`AbstractDiscoveryProcessor` :104/:75). 
`removeProxySelector` then reads `discoveryServiceCache.get(discoveryId)` → 
**null**, but its 
`Optional.ofNullable(dataChangedEventListenerCache.get(...)).ifPresent(...)` 
lambda still runs because the listener-cache key is stale, and calls 
`shenyuDiscoveryService.unWatchInstances(key)` on the null reference. Removing 
a proxy selector after its discovery was deleted therefore throws 
`NullPointerException`, and the `PROXY_SELECTOR` `DELETE` event is never 
published to gateways. (Cleaning the listener cache inside `removeDiscovery` 
instead would make things worse — the delete event would never fire at all.)
   
   <!--
   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-admin -am and ./mvnw 
checkstyle:check -pl shenyu-admin` (module-scoped; full build left to CI).
   
   ### Modifications
   
   - Inside the `ifPresent` lambda, skip only the `unWatchInstances` call when 
the discovery service is already gone (`Objects.nonNull` guard): the listener 
key is still removed and the `PROXY_SELECTOR` delete event still publishes.
   
   ### Verifying this change
   
   - New 
`DefaultDiscoveryProcessorTest#testRemoveProxySelectorAfterDiscoveryRemoved` 
seeds the listener-cache key, removes the service entry (the state 
`removeDiscovery` leaves behind), and asserts `removeProxySelector` completes 
and publishes the delete event. It fails on current master with 
`NullPointerException: Cannot invoke 
"ShenyuInstanceRegisterRepository.unWatchInstances(String)" because 
"shenyuDiscoveryService" is null` and passes with this change.
   - Full `shenyu-admin` module suite green (502 test classes); checkstyle 
green.
   
   ### Notes
   
   - Behavior change: deleting a proxy selector whose discovery was already 
removed now succeeds and publishes the delete event instead of returning 500 
with the event lost.
   - Related but separate latent asymmetry (left untouched here): 
`removeDiscovery` could also drop the stale listener-cache entry — doing that 
alone would suppress the delete event, so the guard is the minimal correct fix; 
maintainers may want both.
   - Orthogonal to open PRs: no open PR touches `AbstractDiscoveryProcessor` 
(checked against the file lists of all 198 open PRs).


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