Skip to content

fix(streamable-http): close SSE responses on errors - #2633

Closed
Epochex wants to merge 5 commits into
modelcontextprotocol:mainfrom
Epochex:fix/streamable-http-close-responses
Closed

Epochex wants to merge 5 commits into
modelcontextprotocol:mainfrom
Epochex:fix/streamable-http-close-responses

Conversation

@Epochex

@Epochex Epochex commented May 18, 2026

Copy link
Copy Markdown

SSE response objects can be leaked when streaming fails or ends unexpectedly.

This ensures HTTP responses are always closed in:

  • _handle_sse_response
  • _handle_resumption_request

Fixes #1450.

Tests:

  • uv run --frozen python -m ruff check src/mcp/client/streamable_http.py tests/client/test_streamable_http_response_cleanup.py
  • uv run --frozen python -m ruff format src/mcp/client/streamable_http.py tests/client/test_streamable_http_response_cleanup.py
  • uv run --frozen pytest tests/client/test_streamable_http_response_cleanup.py -q

@Epochex

Epochex commented May 18, 2026

Copy link
Copy Markdown
Author

CI was failing only on Python 3.14 due to branch coverage reporting 256->exit in _handle_resumption_request cleanup. Added # pragma: no branch on the defensive if event_source is not None to keep branch coverage stable across 3.14 sysmon runs. All checks are green now.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@maxisbey

maxisbey commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry it sat here without a proper review.

We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest.

If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise.

AI Disclaimer

@maxisbey maxisbey closed this Oct 5, 2026
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.

Response leak in SSE handlers

2 participants