stdio_client logs "Process group termination failed ... Operation not permitted" on macOS when terminating a busy child

Ouverte Adaptée aux débutants
#3,929 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
79/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
macos, python

Piste de recherche

Commencez dans mcp/os/posix/utilities.py et examinez la vérification de vie os.killpg(pgid, 0) après l’envoi de SIGTERM. Reproduisez le problème en fermant stdio_client alors que son processus enfant est bloqué, à l’aide du script décrit dans l’issue. Le travail est terminé lorsqu’une terminaison réussie n’émet plus l’avertissement trompeur si la vérification reçoit PermissionError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug v1

Summary

On macOS, closing stdio_client for a child that has to be signalled
(it isn't exiting on stdin EOF) often logs a misleading warning, even
though termination succeeds.

Environment

mcp 1.30.0, Python 3.13, macOS (Darwin 27.2.0, arm64). Not tested on
Linux.

Reproduction

  1. Open stdio_client to a FastMCP stdio server.
  2. Start a tool call that blocks the child, for example a synchronous
    time.sleep(600).
  3. Leave the stdio_client context.
  4. Repeat 10 times.

The script is below.

Expected

No warning when the child is terminated successfully.

Actual

In 4 to 10 of 10 iterations, depending on timing:

WARNING mcp.os.posix.utilities: Process group termination failed for PID 4121: [Errno 1] Operation not permitted, falling back to simple terminate

The fallback process.terminate() succeeds, so nothing breaks, but the
warning is noisy and misleading. It does not occur when the child exits
by itself on stdin EOF, only when SIGTERM is needed.

Likely cause

In mcp/os/posix/utilities.py, after os.killpg(pgid, SIGTERM) the
code polls os.killpg(pgid, 0). Once the child has died but has not
been reaped (a zombie that is the only member of its group), macOS
returns EPERM instead of ESRCH, so the poll raises PermissionError
and the code takes the fallback path.

Treating PermissionError from that liveness poll as "group is gone"
would avoid the warning.

repro_sdk.py (usage: python repro_sdk.py <checkout-with-.venv> 10 hang)
"""usage: repro_sdk.py <project_dir> [iterations] [hang]
Uses only the MCP SDK (mcp 1.30.0): open a stdio_client to a trivial server, leave the context, count
'Process group termination failed' warnings. With `hang` the child is blocked (sync sleep) when closed."""
import asyncio, logging, os, sys, tempfile
logging.basicConfig(level=logging.WARNING, format="%(levelname)s %(name)s: %(message)s")
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
proj = sys.argv[1]; n = int(sys.argv[2]) if len(sys.argv) > 2 else 20; hang = "hang" in sys.argv
tmp = tempfile.mkdtemp()
open(tmp + "/child.py", "w").write(
    "import time\nfrom mcp.server.fastmcp import FastMCP\nm = FastMCP('c')\[email protected]()\ndef hang() -> str:\n    time.sleep(600)\n    return 'x'\[email protected]()\ndef ok() -> str:\n    return 'ok'\nm.run('stdio')\n")


async def one():
    params = StdioServerParameters(command=proj + "/.venv/bin/python", args=[tmp + "/child.py"])
    async with stdio_client(params) as (r, w):
        async with ClientSession(r, w) as s:
            await s.initialize()
            if hang:
                asyncio.create_task(s.call_tool("hang", {}))
                await asyncio.sleep(0.5)
            else:
                await s.call_tool("ok", {})

for i in range(n):
    asyncio.run(one())
print("done", n, "iterations")
Langage dominant
Python
Étoiles
25k
Forks
4.2k
Merge moyen
10 min
PR mergées (30 j)
1

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/python-sdk

Toutes les issues de modelcontextprotocol/python-sdk

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.