modelcontextprotocol / modelcontextprotocol/java-sdk
Servlet transports block Tomcat thread
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 3.7k
- Forks
- 1.1k
- Merge moyen
- 1 j 15 h
- PR mergées (30 j)
- 9
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par HttpServletStreamableServerTransportProvider, HttpServletSseServerTransportProvider et HttpServletStatelessServerTransport, en suivant les endroits où les requêtes entrantes appellent .block() et la manière dont AsyncContext est utilisé. Comparez les chemins de SyncToolSpecification et AsyncToolSpecification, puis vérifiez que les threads des requêtes sont libérés tandis que l’opération réactive se poursuit et se termine avec succès.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100