Skip to content

Fix: --timeout does not stop a hung client - #599

Open
sholub-dev wants to merge 2 commits into
modelcontextprotocol:mainfrom
sholub-dev:fix-client-timeout-kill
Open

sholub-dev wants to merge 2 commits into
modelcontextprotocol:mainfrom
sholub-dev:fix-client-timeout-kill

Conversation

@sholub-dev

Copy link
Copy Markdown

Fixes #598

--timeout didn't stop a hung client when it was started through a shell, so the runner hung forever and left the client running. The client now runs in its own process group and the whole group is killed on timeout. The group is also killed if the runner exits or gets Ctrl+C, since a separate group no longer receives the terminal's signal. On Windows it uses taskkill /T.

Before: --timeout 3000 with a client that never exits ran until killed by hand. After: it reports Client timed out after 3000ms and exits, with no leftover process.

Tests: added a case in src/runner/client.test.ts with a hung client behind a command list. It hangs on main and passes with this change. Lint, type check and the runner tests pass.

@JosephDoUrden JosephDoUrden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this locally on macOS. src/runner/client.test.ts is 5/5 green, and the new test times out on main, so it does catch the bug. I tried to break it: a grandchild that ignores SIGTERM, 3 hung clients in parallel, a setsid escapee, SIGINT and SIGTERM to the runner. The runner settled every time. One gap: closing the terminal (SIGHUP to the runner's process group) now leaves the client running. On main it shared the group and got the hangup too. Adding 'SIGHUP' to the list in trackClient (exit 129) fixed it for me. Otherwise LGTM once CI runs.

@sholub-dev

Copy link
Copy Markdown
Author

Good catch. Applied in 0e465b0.

@JosephDoUrden JosephDoUrden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ran on 0e465b0. src/runner/client.test.ts is 5/5. SIGHUP to the runner or to its process group now exits 129 and takes the client with it, including one that ignores TERM, HUP and INT. On 8a04171 the same SIGHUP left the client running, so the fix is real. SIGINT, SIGTERM and --timeout still behave. macOS only, lgtm.

This branch has not been deployed

No deployments
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.

conformance client --timeout never stops a hung client started through a shell

2 participants