[BUG] MetaDataCache.obtain selects an arbitrary (non-specificity-ordered) matching wildcard MetaData and permanently caches it
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
- Severity: Medium
- Location:
`shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java:122-138` (scan `:125-129`, cache `:133-134`)
-
Description:
On a `CACHE` miss, `obtain` scans `META_DATA_MAP.values().stream().filter(data -> data.getEnabled() && PathMatchUtils.match(data.getPath(), path)).findFirst()`. `META_DATA_MAP` is a `ConcurrentHashMap`; `values()` iteration order is hash-bucket order, not pattern specificity. When two registered metadata paths both match (e.g. `/api/**` and `/api/users/**` both matching `/api/users/42`), the one returned is whichever the CHM yields first — not the more specific one — and that arbitrary choice is pinned into `CACHE.put`. The choice can flip after an unrelated metadata insert/delete triggers a CHM resize (changing bucket layout). Exact (non-wildcard) metadata is pre-cached directly in `cache()` at line 85, so only overlapping-wildcard configs are exposed.
-
Impact:
Non-deterministic / wrong-backend routing when overlapping wildcard metadata exists; cached once chosen.
-
Suggested fix:
Sort matching candidates by specificity (longest non-wildcard prefix / `PathPattern` comparator) before `findFirst`.
-
Confidence: Medium
- Related existing: #6548/#6549/#6550/PERF-04/05 cover unbounded cache and O(n) miss cost; this is the separate selection-arity correctness issue.
---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java at obtain(), especially lines 122-138, and trace the wildcard scan and cache write. Done means overlapping wildcard paths consistently select the most specific matching metadata and cache that deterministic choice; compare the behavior with exact metadata handling in cache() around line 85.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100