Servlet transports block Tomcat thread
まだ誰も着手していません。
評価
調査の方向性
HttpServletStreamableServerTransportProvider、HttpServletSseServerTransportProvider、HttpServletStatelessServerTransport から始め、受信リクエストが .block() を呼び出す箇所と、AsyncContext がどのように使用されているかを追跡します。SyncToolSpecification と AsyncToolSpecification のパスを比較し、その後、リアクティブ操作が継続して正常に完了する間に、リクエストスレッドが解放されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Bug Description
All Servlet-based transports in the SDK (e.g., HttpServletStreamableServerTransportProvider, HttpServletSseServerTransportProvider, HttpServletStatelessServerTransport) call .block() on the Tomcat request thread when processing incoming HTTP requests.
Although AsyncContext is used to hold connections for SSE/streaming, the Tomcat thread remains parked until tool execution completes. As a result, the reactive/async architecture does not provide any real thread efficiency: the request thread stays blocked for the entire duration of the tool call.
With SyncToolSpecification and immediateExecution=false, the tool handler is executed on a separate thread (typically from the boundedElastic pool). This prevents blocking logic from running on the Tomcat thread itself, but the request thread still remains blocked waiting for completion.
With AsyncToolSpecification(via McpAsyncServer), handlers are expected to return fully asynchronous operations (e.g., non-blocking I/O). However, because the transport calls .block(), the HTTP request handling remains synchronous. The handler is not automatically scheduled on another thread unless the developer explicitly does so.
As a result, both SyncToolSpecification and AsyncToolSpecification ultimately block the Tomcat request thread until completion.
I’m not sure if this behavior is intentional. Based on the design of McpAsyncServer, I would expect the transport layer to release the Tomcat thread immediately and allow the reactive pipeline to complete asynchronously. (AsyncContext + subscribe).
@pratik2294
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 9
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/java-sdk のほかの issue
-
area/transport bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/java-sdk#1124 · コメント 1 件 ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities オープンbug P2 ready for work
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modelcontextprotocol/java-sdk#1086 · コメント 1 件 ·
-
enhancement good first issue P3
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/java-sdk#1067 ·
-
bug P2 ready for work
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/java-sdk#898 · コメント 1 件 ·
modelcontextprotocol/java-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
bug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 94/100
objectionary/hone-maven-plugin#1061 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
spring-projects/spring-modulith#1895 ·