Skip to content

fix(util): guard child stdin against post-exit EPIPE - #43258

Closed
Vic563 wants to merge 1 commit into
anomalyco:v2from
Vic563:mcp-stdin-epipe
Closed

Vic563 wants to merge 1 commit into
anomalyco:v2from
Vic563:mcp-stdin-epipe

Conversation

@Vic563

@Vic563 Vic563 commented Aug 18, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #43257

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A local MCP server whose command dies instantly (e.g. its configured cwd no longer exists) crashes the whole v2 background service, and the client respawns it forever — the TUI just loops "restarting service".

The crash is an uncaught EPIPE: broken pipe, send. The MCP transport writes the initialize frame into the child's stdin while it's exiting; once the sink finishes and end() flushes into the broken pipe, the writable's destroy path emits error asynchronously. At that point nothing is subscribed to proc.stdin's error event, so it's process-fatal. Bun 1.4 (which the v2 binary ships with) surfaces this late EPIPE; Bun 1.3 doesn't.

Fix: attach a no-op error listener to proc.stdin in the cross-spawn spawner before wrapping it in the sink. Errors during active writes still reach the sink through its own onError and fail the connect with a typed error as before — this only stops the late, post-sink EPIPE from killing the process.

How did you verify your code works?

  • Added a regression test that connects concurrently to a local MCP command that dies before reading stdin. On Bun 1.4.0-canary it fails 3/3 without the fix (uncaught EPIPE) and passes 3/3 with it; on Bun 1.3.14 it passes either way since 1.3 never surfaces the late EPIPE.
  • Reproduced the original restart loop with my real config against the installed beta, and confirmed the patched spawner survives the same setup.
  • bun run test + bun typecheck in packages/core and packages/util (2 pre-existing failures in core are unrelated: one needs live AWS creds, one is a flaky watcher test that passes in isolation).

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Made with Cursor

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PR Found

PR #41968: fix(cli): survive broken stdio pipes
#41968

This PR appears to be related as it also addresses broken pipe issues in stdio handling. While your current PR (#43258) specifically focuses on guarding child stdin against post-exit EPIPE in the MCP spawner, PR #41968 handles similar broken pipe scenarios in the CLI. Both PRs address process survival when stdio pipes are broken, though in different contexts.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant