Skip to content

fix: surface stateful HTTP session crash cause#2742

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stateful-http-crash-cause
Open

fix: surface stateful HTTP session crash cause#2742
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stateful-http-crash-cause

Conversation

@he-yufeng

Copy link
Copy Markdown

Summary

  • surface the original stateful session app.run() exception when a POST fails after the session stream closes
  • clean up the per-request memory stream on that failure path
  • avoid a secondary ClosedResourceError when reporting the failure back to an already closed writer

Fixes #2741.

To verify

  • python -m pytest tests\server\test_streamable_http_manager.py -q
  • python -m ruff check src\mcp\server\streamable_http.py src\mcp\server\streamable_http_manager.py tests\server\test_streamable_http_manager.py
  • python -m ruff format --check src\mcp\server\streamable_http.py src\mcp\server\streamable_http_manager.py tests\server\test_streamable_http_manager.py
  • git diff --check -- src\mcp\server\streamable_http.py src\mcp\server\streamable_http_manager.py tests\server\test_streamable_http_manager.py

@he-yufeng he-yufeng force-pushed the fix/stateful-http-crash-cause branch from 08bbc28 to fc85da9 Compare June 10, 2026 13:43
@he-yufeng

Copy link
Copy Markdown
Author

Rebased this on current main and carried the crash-cause reporting over the updated streamable HTTP code.

Validation run locally on Windows:

python -m py_compile src\mcp\server\streamable_http.py src\mcp\server\streamable_http_manager.py tests\server\test_streamable_http_manager.py
uv run pytest tests/server/test_streamable_http_manager.py -q -k "session_crash_cause or post_error_message" --basetemp .tmp\pytest-2742-20260610 -p no:cacheprovider
# 2 passed, 20 deselected

git diff --check upstream/main..HEAD

The error log lines in that targeted pytest run are expected: the new regression test deliberately crashes the session runner and asserts that the JSON response reports the original session exception instead of only the downstream closed-stream error.

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.

Stateful Streamable HTTP: in-session exceptions are masked as an empty -32603; real cause only in a separate "Session crashed" log

1 participant