Skip to content

feat(client): make the initialize handshake timeout configurable - #2

Open
julien-camus-sonarsource wants to merge 10 commits into
mainfrom
julien-camus-sonarsource/configurable-handshake-timeout
Open

feat(client): make the initialize handshake timeout configurable#2
julien-camus-sonarsource wants to merge 10 commits into
mainfrom
julien-camus-sonarsource/configurable-handshake-timeout

Conversation

@julien-camus-sonarsource

Copy link
Copy Markdown

Why

request() applies the same 30s ceiling to every JSON-RPC round trip, including initialize. 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 for npx/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 of request/list_tools/call_tool sees 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.
  • The process-liveness poll inside request_with_timeout now 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 — spawns sleep 100 (never speaks the protocol) with a 500ms override and asserts failure well under 5s.
  • test_request_default_timeout_is_unchanged_by_handshake_timeout — same sleep, plain request(), 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/uvx tests fail the same way on unmodified c157b15 in this sandbox (network/package availability, not something this PR touches) — confirmed via git stash.

kageiit and others added 10 commits March 14, 2025 01:39
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.
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.

3 participants