Skip to content

Bound and shield legacy HTTP session cleanup - #3879

Closed
ar-ramchandra wants to merge 1 commit into
modelcontextprotocol:mainfrom
ar-ramchandra:investigate/cancelled-http-session-cleanup
Closed

ar-ramchandra wants to merge 1 commit into
modelcontextprotocol:mainfrom
ar-ramchandra:investigate/cancelled-http-session-cleanup

Conversation

@ar-ramchandra

Copy link
Copy Markdown

Fixes #3877. Original report by @shivamm-gupta.

Cancellation during Streamable HTTP client exit can abort the session-termination DELETE, leaving the legacy session usable on the server. Shield that cleanup request from caller cancellation and bound it to five seconds, then proceed with local transport shutdown. This is a draft candidate pending assignment and agreement on the cleanup budget; it is available for the original reporter or maintainers to build on.

Motivation and Context

With a real Client and stateful server through the in-process HTTP transport, cancelling before DELETE or while DELETE is in progress leaves the old session accepting ping (HTTP 200). With this patch, completed termination makes that session return HTTP 404. Normal exit and the explicit terminate_on_close=False opt-out remain covered.

How Has This Been Tested?

On the local macOS/Python 3.14 environment, ./scripts/test -n 4 passed 6,241 tests with 100% coverage and passed strict-no-cover. The repository pre-commit checks passed, including Ruff, pyright, and markdownlint. Regression cases cover cancellation before and during DELETE, normal exit, the cleanup opt-out, stalled DELETE, and connection failure. The before/during cancellation cases fail against unchanged main at 77001c9; the ordinary-exit and opt-out controls pass there. No live external server or production workload was tested, and the CI platform matrix remains pending.

Breaking Changes

No public signature changes. The proposed five-second total cleanup cap also applies to normal exit, so it can stop a DELETE sooner than a caller's longer HTTP timeout previously allowed. This observable timeout-policy change needs explicit maintainer agreement before the draft is made ready. Caller cancellation can be delayed by up to that cleanup budget; cancellation still propagates afterward.

Types of changes

  • Bug fix
  • New feature
  • Breaking change (the cleanup timeout policy described above)
  • Documentation update

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • AI assistance is disclosed below
  • 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

Investigation, implementation, regression tests, and independent review were AI-assisted with OpenAI Codex. The before/after checks and validation commands above were executed locally. Three test-only no branch annotations address coverage.py's cancellation/context-manager arc accounting; no production branches are newly excluded. A formerly excluded exception handler is now exercised by the connection-failure regression.

Candidate for modelcontextprotocol#3877, reported by @shivamm-gupta. Five-second cleanup budget requires maintainer agreement. AI-assisted with OpenAI Codex.
@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 Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. It's still a draft, but we close those early so you don't put in more time only to have it closed the moment you mark it ready.

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 #3877.

If a maintainer assigns you to #3877, 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 Nov 19, 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.

Unshielded session teardown in streamable_http_client aborts DELETE under cancellation, leaking server session

1 participant