fix: handle EPIPE errors in StdioServerTransport to prevent process crash by stakeswky · Pull Request #1568 · modelcontextprotocol/typescript-sdk
User and others added 2 commits
March 12, 2026 11:23Add error handling for stdout write failures to prevent uncaught EPIPE exceptions when clients disconnect unexpectedly. Changes: - Add stdout error listener in start() to catch EPIPE and other errors - Trigger graceful close when stdout errors occur - Handle write errors in send() by rejecting the promise - Clean up stdout error listener in close() This prevents the Node.js process from crashing when a client disconnects while the server is writing to stdout. Fixes modelcontextprotocol#1564
…r cleanup - Guard send() against closed transport (write on destroyed stream returns false and never drains/errors, hanging the promise) - Fire onerror before onclose in stdout error handler - Idempotent close() via _closed flag - Symmetric error/drain listener cleanup in send() with settled guard - Add changeset and tests covering error path, idempotent close, send rejection during backpressure, and send-after-close
This was referenced
Mar 12, 2026This was referenced
Mar 25, 2026This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters