Skip to content

fix: surface ClientSession transport faults - #3581

Closed
Steeve-Crypto wants to merge 1 commit into
modelcontextprotocol:mainfrom
Steeve-Crypto:fix/1401-clientsession-transport-faults
Closed

Steeve-Crypto wants to merge 1 commit into
modelcontextprotocol:mainfrom
Steeve-Crypto:fix/1401-clientsession-transport-faults

Conversation

@Steeve-Crypto

Copy link
Copy Markdown

Fixes #1401

Summary

Transport-level Exception items on the client read stream were effectively silent in two places:

  1. _default_message_handler (and the mirrored default in Client) only awaited a checkpoint, so faults delivered via _deliver_stream_exception vanished unless a custom message_handler re-raised.
  2. JSONRPCDispatcher._dispatch observed Exception items (or debug-logged them) but did not wake pending send_raw_request waiters — unlike the EOF path, which already fans out CONNECTION_CLOSED via _fan_out_closed.

Fix

  • Default message handlers re-raise Exception items so _deliver_stream_exception logs them (message_handler raised on transport exception).
  • On a transport Exception item, fan out ErrorData(code=CONNECTION_CLOSED, message="Transport error: …") to all pending waiters, then call on_stream_exception as before. The dispatcher is not marked closed (existing tests require the receive loop to keep serving after a single Exception item).

Minimal and backwards-compatible: no new public APIs or error taxonomy.

Motivation and Context

Without this, in-flight client requests can hang when the transport yields an Exception (e.g. read timeout), which matches the production hang described on #1401.

How Has This Been Tested?

uv run pytest tests/client/test_session.py tests/shared/test_jsonrpc_dispatcher.py -q --tb=short

Result: 172 passed (including two new regression tests).

New coverage:

  • Default message_handler re-raises a transport Exception and is logged via _deliver_stream_exception.
  • A pending send_raw_request raises MCPError(CONNECTION_CLOSED) promptly when an Exception arrives on the read stream; the loop still handles a later inbound request.

Breaking Changes

None intended. Callers that previously hung on transport faults will now see MCPError(CONNECTION_CLOSED) (or a logged re-raise from the default message handler). Custom handlers that already handled Exception items are unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • I have disclosed any AI assistance and can explain the change in my own words
  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Issue #1401 is labeled ready for work / good first issue / P1 / bug but is not assigned and does not carry help wanted. Per CONTRIBUTING, the require-linked-issue bot may auto-close this PR until a maintainer assigns the issue (or adds help wanted). Branch left intact for reopen — please assign if this approach looks right.

AI assistance: This change was prepared with AI assistance (implementation draft and test scaffolding). I reviewed the surrounding contracts (_fan_out_closed, existing transport-exception tests) and can explain / adjust the patch.

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Sep 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #1401.

If a maintainer assigns you to #1401, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientSession Error Handling

1 participant