[BUG] Request/Response transformer ChatClientCache uses non-thread-safe HashMap
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
- severity: High
- files: `shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/cache/ChatClientCache.java:31`; `.../ai-response-transformer/.../cache/ChatClientCache.java:31`
- description: Both caches back a shared singleton with `private static final Map CHAT_CLIENT_MAP = new HashMap<>()` and expose `init`(put)/`getClient`(get)/`destroyClient`(remove). These are mutated from the sync-data thread and read from reactive request threads. `HashMap` is not safe for concurrent read/write: structural modifications during `get`/`put` can corrupt the table or loop indefinitely. The AI-proxy `ChatClientCache` correctly uses `ConcurrentHashMap`; these two do not.
- impact: Lost/stale ChatClient entries, corrupted map structure, or stuck CPU under concurrent rule updates and traffic.
- suggested_fix: Replace `new HashMap<>()` with `new ConcurrentHashMap<>()` in both caches.
- confidence: High
- related_existing: none — #6470/#6471 are about the AI-proxy plugin, not these transformer caches.
---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the two named ChatClientCache.java files in the request-transformer and response-transformer modules, then compare them with the AI-proxy ChatClientCache mentioned in the issue. Verify the init, getClient, and destroyClient entry points under concurrent sync-data updates and request traffic; done means both transformer caches use a thread-safe map without changing their interfaces.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100