Skip to content

Fix abort signal listener leak in _requestWithSchema#1672

Open
lucaalbinati wants to merge 1 commit intomodelcontextprotocol:mainfrom
lucaalbinati:fix/abort-signal-listener-leak
Open

Fix abort signal listener leak in _requestWithSchema#1672
lucaalbinati wants to merge 1 commit intomodelcontextprotocol:mainfrom
lucaalbinati:fix/abort-signal-listener-leak

Conversation

@lucaalbinati
Copy link

Summary

  • The abort listener added to the caller's AbortSignal in _requestWithSchema was never removed, causing listeners to accumulate across requests sharing the same signal
  • Named the anonymous listener, added explicit removeEventListener on all exit paths (response handler, cancel, timeout, transport send failure, task enqueue failure), and added once: true as a defensive fallback

Test plan

  • Added 5 tests covering listener cleanup on all exit paths:
    • Successful response
    • Timeout
    • Multiple sequential requests on the same signal (no accumulation)
    • Abort signal triggered
    • Transport send failure
  • Verified all 5 tests fail without the fix and pass with it

The abort listener added to the caller's signal was never removed,
causing listeners to accumulate across requests sharing the same signal.

Named the listener, added explicit removeEventListener on all exit
paths, and added once:true as a defensive fallback.
@lucaalbinati lucaalbinati requested a review from a team as a code owner March 12, 2026 08:50
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

⚠️ No Changeset found

Latest commit: 937f690

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1672

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1672

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1672

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1672

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1672

commit: 9c9881d

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