Skip to content

Handle BrokenResourceError in stdio client shutdown path#2143

Open
aframedelta wants to merge 1 commit intomodelcontextprotocol:mainfrom
aframedelta:fix-1564-stdio-broken-resource
Open

Handle BrokenResourceError in stdio client shutdown path#2143
aframedelta wants to merge 1 commit intomodelcontextprotocol:mainfrom
aframedelta:fix-1564-stdio-broken-resource

Conversation

@aframedelta
Copy link

Summary

  • handle anyio.BrokenResourceError in stdio client reader/writer loops
  • add regression test for an immediately-exiting stdio server path

Why

Related to #1564.

When the subprocess stdio closes abruptly during client initialization, BrokenResourceError may escape from stream tasks and surface as an unhelpful TaskGroup failure instead of a clean MCP connection-closed path.

Changes

  • catch anyio.BrokenResourceError alongside ClosedResourceError in:
    • stdout_reader
    • stdin_writer
  • add test_stdio_client_exits_immediately_surfaces_connection_closed

Validation

  • . .venv/bin/activate && pytest tests/client/test_stdio.py -q -k "bad_path or exits_immediately or nonexistent_command"
    • 3 passed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant