apache / apache/shenyu

[BUG] ShenyuStreamableHttpServerTransportProvider.createSessionAndRestoreId leaks sessions

Open
#6,644 2 comments 0 reactions 1 assignee Claimed by @wy471x View on GitHub
feature: plugin priority: high type: bug
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-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/transport/ShenyuStreamableHttpServerTransportProvider.java:461-490`
- description: When a client sends a request with a `sessionId` that does not exist (server restart, timeout, stale client), `createSessionAndRestoreId` creates a new `McpServerSession`+`StreamableHttpSessionTransport`, stores them in `sessions`/`sessionTransports`, and processes one request — but, unlike `createTemporarySessionAndProcess` (which has a `.doFinally(...removeSession...)`), the restore path has no cleanup hook. The session and transport remain in both maps forever.
- impact: Unbounded memory growth of `sessions`/`sessionTransports`/`ShenyuMcpExchangeHolder` via the stale-session restore path.
- suggested_fix: Add a `doFinally` to `createSessionAndRestoreId` that calls `removeSession(actualSessionId)` and `ShenyuMcpExchangeHolder.remove(actualSessionId)`.
- confidence: High
- related_existing: none — #6473/#6117 are different defects.

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

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.