[Server][Streamable HTTP] Concurrent SSE streams on one session can consume each other's client responses
Les mainteneurs répondent en général sous 2 jours
Une pull request liée a déjà été fusionnée.
- #556 par @mglaman — fusionnée
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 25/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- php
- Domaine
- backend-api-design
Piste de recherche
Start with StreamableHttpTransport::createStreamedResponse() and the getPendingRequests() and checkForResponse() calls described in the issue; trace how yielded request IDs relate to each stream's fiber. Check linked pull request #556, which is already open. Done means concurrent streams on one session cannot consume or time out each other's responses.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
On Streamable HTTP (handshake era, SSE), two tool calls on one session that both send a server-to-client request, such as elicitation/create, can each receive the other's answer.
Cause
Protocol keeps pending server-to-client requests in one session-wide list, _mcp.pending_requests. The SSE loop in StreamableHttpTransport::createStreamedResponse() walks that whole list, not only the requests its own fiber sent:
$pendingRequests = $this->getPendingRequests($this->sessionId);
// ...
foreach ($pendingRequests as $pending) {
$response = $this->checkForResponse($pending['request_id'], $this->sessionId);
if (null !== $response) {
$yielded = $this->sessionFiber->resume($response);
// ...
With tool calls A and B open on one session, each waiting in ClientGateway::elicit():
- The client answers B's elicitation.
- A's loop polls first, finds B's answer, consumes it, and resumes A's fiber with it. A's tool continues with B's answer.
- B's answer is gone from the session. B's tool waits until its 120-second timeout.
The timeout branch has the same problem: A's loop can resume A's fiber with a timeout error for B's request ID.
I found this by reading the source on main (a5ed85f) and 0.8.1. I have not reproduced it end to end. Running two streams on one session at the same time needs a server that doesn't serialize requests per session.
Suggested fix
Record which stream sent each pending request, and have each loop check only its own. For example, track the request IDs the fiber yielded in the transport instance, and filter getPendingRequests() by them.
Context
In Drupal's mcp_server we lock the session for the length of a stream. That lock made a second elicitation wait, which hid this bug. We're changing the lock to cover each session write instead of the whole stream, so elicitation answers don't wait on the lease (mcp_server!88). That makes this race reachable.
- Langage dominant
- PHP
- Étoiles
- 1.6k
- Forks
- 180
- Merge moyen
- 3 j 2 h
- PR mergées (30 j)
- 55
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire 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.
Autres issues de modelcontextprotocol/php-sdk
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStanOuverteServer
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
modelcontextprotocol/php-sdk#468 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Builder::build() silently skips configured file-based discovery when symfony/finder is missing — should fail loudlyPeut-être pris @ousamabenyounes l’a pris il y a 58 jours. Ouverteneeds confirmation needs maintainer action Server
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
modelcontextprotocol/php-sdk#398 · 1 réaction ·
Les mainteneurs répondent en général sous 2 jours
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
modelcontextprotocol/php-sdk#370 ·
Les mainteneurs répondent en général sous 2 jours
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
modelcontextprotocol/php-sdk#587 ·
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 3/5 Une demi-journée Accessibilité débutants 60/100
modelcontextprotocol/php-sdk#586 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de modelcontextprotocol/php-sdk
Issues similaires
-
HttpRequestTrait fatals on WordPress 7.2: $blocked_http_requests clashes with WP_UnitTestCase_BaseOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
pluginsGLPI/addressing#127 ·