Repository navigation
fix(core): enforce maxTotalTimeout as a hard cap - #3155
Draft
Sanath91009 wants to merge 1 commit into
Draft
Sanath91009 wants to merge 1 commit into
Sanath91009 wants to merge 1 commit into
Conversation
_setupTimeout armed the pending timer with `timeout` only, so `maxTotalTimeout` was read solely in `_resetTimeout`, which runs only on a progress notification with `resetTimeoutOnProgress`. A request that never sends progress outlived its documented hard cap, and a progress reset re-armed the full `timeout` instead of the remaining total budget. Arm the timer with min(timeout, remaining maxTotalTimeout), re-arm with the remaining budget on reset, and report `Maximum total timeout exceeded` when the cap is what fired.
🦋 Changeset detectedLatest commit: 5e065c8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Fixes #2695.
maxTotalTimeoutis documented as a hard cap, but_setupTimeoutarmed the pending timer withtimeoutonly. The cap was read in_resetTimeout, which runs only when anotifications/progressarrives withresetTimeoutOnProgressset. A request that never sends progress therefore outlived its own deadline, and a progress reset re-armed the fulltimeoutinstead of what was left of the total budget.Reproduction
On
mainat1e608ca,TestProtocolover aMockTransportthat swallows the request:Request timed out; the 150ms cap did nothing.{ timeout: 1000, maxTotalTimeout: 300, resetTimeoutOnProgress: true }and one progress notification at 200ms, the timer is re-armed for the full 1000ms, so the request settles at 1200ms instead of 300ms.Change
_setupTimeoutarms the timer withmin(timeout, remaining maxTotalTimeout)._resetTimeoutre-arms with the remaining total budget rather than the fulltimeout.Maximum total timeout exceededand{ maxTotalTimeout, totalElapsed }instead ofRequest timed out.inputRequiredDriverpasses a shrinking remaining budget back in asmaxTotalTimeout, so it gets the same bound per leg.Tests
Three tests added to
packages/core-internal/test/shared/protocol.test.ts:should enforce maxTotalTimeout when no progress notification arrives— fails onmain, passes with the fix.should re-arm the timeout within the remaining maxTotalTimeout budget— fails onmain, passes with the fix.should still report the per-request timeout when it is shorter than maxTotalTimeout— guard, passes both ways.Verified by reverting only
protocol.ts: 2 failed, 2 passed. With the fix: 4 passed.Full suites green:
packages/core-internal78 files / 1853 tests,packages/server55 files / 674 tests.tsgo --noEmit, ESLint and Prettier clean. Changeset added.Note on #2763
#2763 covers the same issue and has been conflicted against
mainsince 2026-09-23. I did not want to add a third duplicate, but a PR that cannot merge does not fix the bug. Happy to close this one if @claxman rebases and it lands first.