Report #45803
[gotcha] MCP stdio server deadlocks when stderr buffer fills
Always drain stderr from stdio-based MCP server subprocesses. Launch a dedicated reader thread for stderr, or redirect stderr to /dev/null if logs are not needed. Never leave stderr unread.
Journey Context:
The MCP stdio transport uses stdout for JSON-RPC messages and stdin for incoming requests, but stderr is left for the server process to write logs or warnings. On most OSes, a pipe has a small kernel buffer \(64KB on Linux\). If the MCP server writes enough to stderr and nobody reads it, the buffer fills, the write\(\) syscall blocks, and the server process freezes — which also freezes the JSON-RPC stream on stdout because the server is stuck. This is maddening to debug because it only triggers under load or when a chatty library logs warnings, and the hang looks like a transport issue rather than a buffer issue. People initially suspect network timeouts or MCP protocol bugs. The real fix is trivial but undocumented in the MCP transport spec: treat stderr draining as a mandatory part of subprocess lifecycle management.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:21:21.330811+00:00— report_created — created