feat(client): make the initialize handshake timeout configurable - #2
Open
julien-camus-sonarsource wants to merge 10 commits into
Open
feat(client): make the initialize handshake timeout configurable#2julien-camus-sonarsource wants to merge 10 commits into
julien-camus-sonarsource wants to merge 10 commits into
Conversation
request() applies the same 30s ceiling to every JSON-RPC round trip, including initialize. That's fine for steady-state calls (list_tools, call_tool) against a server that's already running, but it also caps how long a command is given to start in the first place -- and for commands like `npx`/`uvx`, "start" can include downloading and installing a package on first run. A consumer with a slow registry or a large package has no way to give that one-time cost more room without also loosening detection of a genuinely hung steady-state call. Split the two: `request_with_timeout` takes an explicit timeout and `request` keeps calling it with the existing 30s default, so no caller of `request`, `list_tools`, or `call_tool` sees a behavior change. `initialize_with_timeout` and `ClientBuilder::handshake_timeout` do the same for the handshake specifically -- `spawn_and_initialize` uses the override when set, or the unchanged 30s default otherwise.
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.
Why
request()applies the same 30s ceiling to every JSON-RPC round trip, includinginitialize. That's the right default for steady-state calls against a server that's already running, but it also caps how long the startup command has to get there — and fornpx/uvx-based servers, startup can include downloading and installing a package on first run. A consumer with a slower registry or a larger package currently has no way to give that one-time cost more room without also loosening detection of a genuinely hung steady-state call.Needed by Gitar's custom-integration feature (private npm registries): the 30s budget is comfortably enough for a small server, but times out on a cold cache for a mid-size one, confirmed in both staging and prod.
What changed
Client::request_with_timeout(method, params, timeout)—request()now delegates to it with the existing 30s default, so no caller ofrequest/list_tools/call_toolsees a behavior change.Client::initialize_with_timeout(implementation, capabilities, timeout)— same split for the handshake;initialize()delegates with 30s.ClientBuilder::handshake_timeout(Duration)— opt-in override;spawn_and_initialize()uses it when set, otherwise unchanged 30s default.request_with_timeoutnow scales its iteration count to the given timeout instead of being hardcoded to 100 * 300ms.Testing
Two new tests in
src/client/test.rs:test_handshake_timeout_overrides_the_default— spawnssleep 100(never speaks the protocol) with a 500ms override and asserts failure well under 5s.test_request_default_timeout_is_unchanged_by_handshake_timeout— samesleep, plainrequest(), asserts it's still pending after a 2s probe (i.e. hasn't fallen back to some other short timeout).The 11 pre-existing
notes-simple/uvxtests fail the same way on unmodifiedc157b15in this sandbox (network/package availability, not something this PR touches) — confirmed viagit stash.