stdio server stops answering queued requests under CPU contention until more input arrives (lost wakeup?)

オープン
#3,964 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python

調査の方向性

Start at the FastMCP stdio server’s request-reading and response-dispatch path, then trace how AnyIO worker results wake the asyncio loop under CPU contention. Reproduce with the described driver: send the request lines in one write and leave stdin open while waiting for the missing responses. Done when every request receives a response under contention without needing another input message.

索引モデルが issue の本文から書いたものです。

説明

Versions: mcp 1.30.0, anyio 4.16.0, CPython 3.14.7, Linux x86_64.

What happens. A FastMCP stdio server, given several requests in one write, sometimes answers the first few and
then stops: the remaining requests (and a final ping) get no response, with stdin still open, for as long as we
waited (90 s). It happens only under CPU contention. Alone it answered every time (0 of 10 runs stalled). With eight
copies running at once on four cores, 6 of 48 runs stalled. The point where it stops varies between runs: the
missing ids were {6, 7, 999}, {7, 999} or {999}.

Minimal server (no application code):

from mcp.server.fastmcp import FastMCP
m = FastMCP("bare")
@m.tool()
def recall(query: str) -> str:
    return "ok"
m.run()

Driver. One write to stdin of these lines, then wait (stdin left open) for responses to ids 3, 4, 6, 7 and 999:
initialize (id 1); notifications/initialized; a malformed line ({not json ...); a request with an unknown
method (id 2); tools/call of an unknown tool (id 3); tools/call of recall with an unknown argument (id 4); a
tools/call whose params is a string (id 5); a batch array; prompts/get of an unknown prompt (id 6);
resources/read of an unknown URI (id 7); ping (id 999).

Stack dump of a stalled server (faulthandler, SIGABRT after 30 s without a response): the main thread is idle in
the asyncio loop's select (epoll_wait), and the AnyIO worker threads are idle in queue.get. No request handler
is running, and nothing is blocked. That looks like a result handed back to the loop without the loop being woken:
a further message sent after the stall gets the outstanding responses answered: a driver that sends an extra
ping after 5 s of silence saw 3 of 40 runs stall under the same load, and all 3 completed after the ping.

Expected: every request read from stdin is eventually answered while stdin is open, whatever the CPU load.

Happy to provide the full driver script and dumps.

主要言語
Python
スター
25k
フォーク
4.2k
平均マージ
10分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/python-sdk のほかの issue

modelcontextprotocol/python-sdk の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。