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

   Fixes #7977.
   
   ## Problem
   
   `AbstractShenyuPlugin` writes a negative (empty-id) selector or rule entry 
under `(pluginName, path)` whenever nothing matches. The blank-id branch in 
`cacheSelectorData` / `cacheRuleData` returns before the all-`uri` eligibility 
check, so a request that only missed because a header was absent poisons the 
path for the whole TTL (60 s by default): the next request carrying that header 
is short-circuited and `doExecute` is never called. `defaultMatchRule` / 
`cacheRuleData` have the same pattern.
   
   In-process reproduction (real `BaseDataCache` / `MatchDataCache`, 
`MockServerWebExchange`, `execute(...).block()`):
   
   1. selector A requires `header X-Tenant = a`;
   2. `GET /x` without the header misses and caches an empty selector;
   3. `GET /x` with `X-Tenant: a` still does not match;
   4. clearing only the selector match cache makes step 3 match.
   
   The same two-request sequence repros for a rule miss.
   
   ## Change
   
   - Add `isUriOnlyConditionList` and candidate-set predicates. A negative 
entry is cached only when every **enabled** candidate is determined by the 
path: no RESTful matching, and (for `CUSTOM_FLOW` selectors, and for rules) 
every condition is `uri`.
   - Empty condition lists are treated as path-determined: a `CUSTOM_FLOW` 
selector with no conditions never matches, and empty rule conditions are 
request-independent. Disabled entries are skipped because matching already 
ignores them.
   - Gate only the two negative-cache call sites. Positive-cache eligibility is 
deliberately untouched (#7981).
   - The rule guard additionally requires the **whole selector set** to be 
path-determined. `MatchDataCache` keys rule entries by `(pluginName, path)` 
with no selector id, so a negative rule entry written for selector A would 
otherwise also suppress selector B on the same path. Positive cross-selector 
rule reuse remains #7976 and is not changed here.
   
   ## Tests
   
   Five new cases in `AbstractShenyuPluginTest`:
   
   - A selector miss caused by a missing header is not cached, and the next 
header-bearing request reaches `doExecute`.
   - The same two-request sequence for a rule miss.
   - A rule miss is not cached while the selector set is dynamic (path-only 
rule cache key).
   - Two positive controls: path-only selector/rule candidate sets still cache 
negative entries, so the optimization is preserved.
   
   Red on `master`: the three negative-cache assertions fail with an empty 
`SelectorData` / `RuleData` already present. Green after the change.
   
   ## Verification
   
   ```bash
   # AbstractShenyuPluginTest 19/19
   ./mvnw -pl shenyu-plugin/shenyu-plugin-base -DskipTests=false 
-Dtest=AbstractShenyuPluginTest test
   
   # Full module tests 302/302
   ./mvnw -pl shenyu-plugin/shenyu-plugin-base -DskipTests=false test
   
   # Checkstyle clean
   ./mvnw -pl shenyu-plugin/shenyu-plugin-base checkstyle:check
   ```


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