DefaultJsonSchemaValidator: schema cache grows without bound (no TTL or size limit)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 48/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- java
- 領域
- backend, performance
研究方向
Read DefaultJsonSchemaValidator.java in both the Jackson 2 and Jackson 3 modules, then inspect the existing cache tests and clearCache() behavior. Compare bounded cache policies such as a size limit or TTL and check how each behaves with repeated unique schemas. Done means cache growth is bounded while schema validation continues to work; the issue does not identify specific test files.
由索引模型根據 Issue 內容生成。
描述
Summary
DefaultJsonSchemaValidator keeps compiled NetworkNT Schema instances in a ConcurrentHashMap forever. There is an explicit TODO to add eviction; nothing purges entries on tool/schema updates or long-running servers.
Affected code
mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson2/DefaultJsonSchemaValidator.javamcp-json-jackson3/src/main/java/io/modelcontextprotocol/json/schema/jackson3/DefaultJsonSchemaValidator.java
// TODO: Implement a strategy to purge the cache (TTL, size limit, etc.)
private final ConcurrentHashMap<String, Schema> schemaCache;
clearCache() exists for tests but is not wired into server lifecycle or dynamic tool registration.
Steps to reproduce
- Run a server that repeatedly
addTool/ updates tools with distinctinputSchema/outputSchemamaps (or stress-test the validator in a loop with unique schemas). - Monitor heap or call
getCacheSize()on a test instance. - Observe cache size monotonically increases; entries are never removed.
Expected behavior
Bounded memory for schema compilation cache, for example:
- max entries + LRU, and/or
- TTL, and/or
- invalidation when tools/schemas are removed or replaced
Actual behavior
Every distinct cache key retains a compiled Schema for the JVM lifetime.
Impact
Long-lived MCP servers with dynamic tool catalogs or many unique schemas may accumulate unbounded native/heap pressure over days or weeks.
Related
- #1328 — incorrect cache keys (correctness); this issue is resource / lifecycle
- Dynamic tool APIs:
McpAsyncServer#addTool, etc.
Suggested direction
Content-addressed keys (fixing $id/hash issues) plus a bounded cache policy documented if needed.
- 主要語言
- Java
- 星號
- 3.8k
- 分支
- 1.1k
- 平均合併
- 1 天 3 小時
- 30 天內合併 PR
- 38
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/java-sdk 的其他 Issue
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON string可能已有人在做 @starryeye 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
modelcontextprotocol/java-sdk#1352 · 1 則留言 ·
維護者通常 1 天內回覆
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was called未關閉
難度 1/5 1 小時以內 新手友好度 85/100
modelcontextprotocol/java-sdk#1346 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 64/100
modelcontextprotocol/java-sdk#1345 · 1 則留言 ·
維護者通常 1 天內回覆
-
area/server legacy P3
難度 2/5 1-3 小時 新手友好度 72/100
modelcontextprotocol/java-sdk#1330 · 1 則留言 ·
維護者通常 1 天內回覆
-
Client request handlers that complete empty send no JSON-RPC response可能已有人在做 @1fanwang 於 83 天前認領。 未關閉area/client bug P2
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 6 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
-
crash
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 2/5 1-3 小時 新手友好度 74/100
-
account bug course exam iris lecture
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆