DefaultJsonSchemaValidator: schema cache grows without bound (no TTL or size limit)

Đang mở
#1,344 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend, performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.java
  • mcp-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

  1. Run a server that repeatedly addTool / updates tools with distinct inputSchema / outputSchema maps (or stress-test the validator in a loop with unique schemas).
  2. Monitor heap or call getCacheSize() on a test instance.
  3. 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.

Ngôn ngữ chính
Java
Star
3.8k
Fork
1.1k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
38

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/java-sdk

Tất cả issue của modelcontextprotocol/java-sdk

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.