fix(everything): stop long-running operation when the request is cancelled - #4847
Open
Ewertonslv wants to merge 1 commit into
Open
Ewertonslv wants to merge 1 commit into
Ewertonslv wants to merge 1 commit into
Conversation
…elled trigger-long-running-operation waited on plain setTimeout promises and never looked at extra.signal, so after a client cancelled the request the loop kept running and sending progress notifications. On stdio this held the process open and delayed shutdown. Wait with node:timers/promises setTimeout and pass the request signal, so the pending timer is cleared and the handler rejects as soon as the request is aborted. Fixes modelcontextprotocol#4846
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
trigger-long-running-operationwaited on plainsetTimeoutpromises and never checkedextra.signal. When a client cancelled the request, the loop kept running to the end and kept sending progress notifications. On stdio the pending timers held the process open, which is what delays shutdown in #4846.The wait now uses
setTimeoutfromnode:timers/promiseswith the request's abort signal. When the request is cancelled, the pending timer is cleared and the handler rejects immediately, so no further steps or progress notifications run.Fixes #4846
Server Details
trigger-long-running-operation)Motivation and Context
The Everything server is the reference for how MCP features should behave. A long-running tool that ignores cancellation shows the wrong pattern, and it keeps stdio clients from shutting down cleanly after a cancel.
How Has This Been Tested?
Added
should stop when the request is cancelledtosrc/everything/__tests__/tools.test.ts. It starts the operation with anAbortControllersignal, aborts after 50 ms, and asserts that the handler settles within 500 ms without sending any progress notification.expected 'still running' to be 'stopped'.npx vitest run __tests__/tools.test.ts: 62 passed.npx tsc --noEmit: clean.I did not test it against an LLM client.
Breaking Changes
None. Calls that are not cancelled behave the same as before.
Types of changes
Checklist