{"record":{"id":"8fa53522f91b130b","repo":"Hmbown/CodeWhale","slug":"mcp-server-server-process-closed-stdout-befor","errorCode":null,"errorMessage":"MCP server '{server}': process closed stdout before answering {method}{}","messagePattern":"MCP server '(.+?)': process closed stdout before answering (.+?)(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mcp/src/stdio_client.rs","lineNumber":901,"sourceCode":"\n        let deadline = Instant::now() + timeout;\n        loop {\n            let remaining = deadline.saturating_duration_since(Instant::now());\n            if remaining.is_zero() {\n                bail!(\"MCP server '{server}': {method} timed out after {timeout:?}\");\n            }\n            let line = match self.responses.recv_timeout(remaining) {\n                Ok(ChildStdoutMessage::Line(line)) => line,\n                Ok(ChildStdoutMessage::Invalid(error)) => {\n                    bail!(\n                        \"MCP server '{server}': invalid child stdout while awaiting {method}: {error}\"\n                    );\n                }\n                Err(RecvTimeoutError::Timeout) => {\n                    bail!(\"MCP server '{server}': {method} timed out after {timeout:?}\");\n                }\n                Err(RecvTimeoutError::Disconnected) => {\n                    bail!(\n                        \"MCP server '{server}': process closed stdout before answering {method}{}\",\n                        self.exit_note()\n                    );\n                }\n            };\n\n            // Servers occasionally emit banners or log lines on stdout. They\n            // are skipped; only the matching response ends the wait. Valid\n            // requests and notifications are handled by the reader before\n            // they reach this rendezvous.\n            let Ok(message) = serde_json::from_str::<Value>(&line) else {\n                continue;\n            };\n            if message.get(\"jsonrpc\").and_then(Value::as_str) != Some(\"2.0\") {\n                bail!(\n                    \"MCP server '{server}': {method} received a child message without jsonrpc \\\"2.0\\\"\"\n                );\n            }","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/mcp/src/stdio_client.rs#L883-L919","documentation":"When the reader thread sees EOF on the child's stdout, it drops the response channel; request() then receives RecvTimeoutError::Disconnected and bails with this message plus the child's exit status (exit_note). It reports that the MCP server process terminated before delivering an answer.","triggerScenarios":"The child process exits or closes its stdout while request() is awaiting a response — crash, clean exit, or killed process — before the timeout expires.","commonSituations":"Server crashed handling the request; process killed by OOM/signal; npx/uvx wrapper exiting due to fetch failure; server exiting after an internal error.","solutions":["Read the appended exit_note (exit code/signal) and the child's stderr to identify the cause of death.","Run the server command manually and invoke the same method to reproduce the crash.","Check for OOM kills or external signals (dmesg, journalctl).","Update or pin the server version if a known crash regression."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// detect a dead child before issuing a request\nfn is_usable(client: &ChildProcessMcpClient) -> bool {\n    !client.has_exited()\n}","typeGuard":null,"tryCatchPattern":"match client.request(method, params, timeout) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"closed stdout\") => {\n        // exit_note in the message carries status; restart the server and retry once\n        eprintln!(\"MCP server exited: {e}\");\n        respawn_and_retry(method, params)?\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Capture and persist child stderr to diagnose repeated exits.","Check dmesg/journalctl for OOM or signal kills when this appears sporadically.","Verify the wrapper (npx/uvx) can resolve its package offline/online as needed.","Auto-respawn with backoff, but cap retries — repeated exits are a server bug."],"tags":["mcp","process-crash","stdio"],"backgroundTag":"connection-closed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}