Emryswu opened a new pull request, #7541:
URL: https://github.com/apache/shenyu/pull/7541

   Fixes #7452
   
   ### Problem
   
   `CachePluginDataHandler.handlerRule()` skips a rule whose `handle` is null, 
so no `CacheRuleHandle` is cached for it. When such a rule matches, 
`CachePlugin` still wraps the response in `CacheHttpResponse` with a null 
handle, and `cacheResponse()` throws a `NullPointerException` on 
`cacheRuleHandle.getTimeoutSeconds()` while writing an otherwise successful 
downstream response.
   
   ### Fix
   
   `CachePlugin.doExecute()` now looks up the rule handle first. If none is 
cached, it passes the request to the rest of the chain without reading or 
writing the cache. This is how the Hystrix, Resilience4J, Sentinel and 
RateLimiter plugins handle a missing handle since #6877. No default timeout is 
applied. Rules with a handle behave as before. The handle is now looked up once 
instead of in both branches.
   
   ### Tests
   
   Added two tests to `CachePluginTest`. In both, the downstream chain writes a 
real response body:
   
   - `testDoExecuteSkipsCacheWhenRuleHandleIsNull`: a rule with no cached 
handle completes without error, returns the downstream body, and writes nothing 
to the cache. Without the fix, this test fails with the NPE from the issue.
   - `testDoExecuteCachesResponseWhenRuleHandleIsPresent`: a rule with a handle 
still returns the body and caches it.
   
   `mvn -pl shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-handler -am 
test` passes locally, checkstyle included.
   
   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.
   - [ ] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.
   


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