modelcontextprotocol / modelcontextprotocol/java-sdk

DefaultMcpTransportSession#closeGracefully leaks resources on incomplete DELETE response

Open
#547 6 comments 0 reactions 1 assignee View on GitHub

@Kehrlann is already working on this.

Since Aug 27, 2026.

bug P2
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

Bug description
When the MCP server is abnormal, the statement this.onClose.apply(this.sessionId.get()) in the closeGracefully method of DefaultMcpTransportSession.java throws an exception, so this.openConnections::dispose is never executed and may leak resources.

Environment
Java version: 21
mcp-bom: 0.11.3

Steps to reproduce
1、Create an McpSyncClient.
2、Execute client.initialize(); client.listTools();
3、Suspend the debugger at client.closeGracefully();
4、Make the MCP server unavailable.
5、Resume execution of client.closeGracefully();

Expected behavior
this.openConnections::dispose should always be executed.

Minimal Complete Reproducible example
McpSyncClient client = McpClient.sync(transport)
.requestTimeout(Duration.ofSeconds(10))
.build();

// Initialize connection
client.initialize();

// List available tools
ListToolsResult tools = client.listTools();

// Close client
client.closeGracefully();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.