Repository navigation
fix(core): enforce maxTotalTimeout as a hard cap - #3155
Sanath91009 wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 7c23d71 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: |
_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.
5e065c8 to
16b4464
Compare
|
Rebased onto CI is green on Local |
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.