Repository navigation
Closed
Labels
Description
Summary
execSSH applies one hardcoded 30s timeout to every command, including long-running, state-changing operations. These routinely take longer than 30s on a Pi, so the tool reports a timeout while the work is still running or has been interrupted.
Where
mcp-server/src/utils/ssh-api.ts:30(EXEC_TIMEOUT_MS = 30_000),:111-115- Long-running callers:
aptUpdate.ts:21-24,backupRun.ts:24,volumeBackup.ts:28,backupRestore.ts:39,composePull.ts:32,composeUp.ts:37,containerScan.ts:41,certRenew.ts:44-46,diskUsage.ts:34,logSearch.ts:35
Details
The timer covers the connect and the whole command. When it fires, the code calls conn.end() and rejects with SSHTimeoutError. It sends no signal to the remote process, and no tool can override the timeout. apt-get upgrade -y also runs without DEBIAN_FRONTEND=noninteractive, so a conffile prompt waits until the timeout.
Impact
- apt upgrade, restic backup or restore, compose pull of all stacks, and Trivy scans are all reported as failures even when they succeed.
- Closing the channel can SIGPIPE a process that writes progress to stdout, which can leave dpkg half-configured or a restic lock behind.
- An agent that sees "timed out" may retry a non-idempotent operation while the first run is still going.
Steps to reproduce
- Call
homelab_aptUpdate {upgrade: true}on a Pi with pending updates, orhomelab_containerScan {}with several images. - After 30s you get
SSHTimeoutError. The remote process is still running (pgrep apt/pgrep trivy).
Suggested fix
- Add an options argument:
execSSH(command, node, { timeoutMs }). - Give heavy tools their own budgets (for example 10-30 min), and make the default overridable via an env var.
- On timeout, signal or close the channel, or wrap the remote command in
timeout <n>. - For very long jobs, consider running them detached (
systemd-run/nohup) and returning a job handle to poll. - Set
DEBIAN_FRONTEND=noninteractiveand-o Dpkg::Options::=--force-confoldfor upgrades.
Acceptance criteria
-
execSSHaccepts a per-call timeout - Each long-running tool sets an appropriate timeout
- On timeout the remote process is terminated, or the error says it may still be running
- Test with fake timers covers the timeout path
Getting started
- Relevant files:
mcp-server/src/utils/ssh-api.ts, the tool files listed above - How to run tests:
cd mcp-server && npm test
Filed by repo-audit/full-audit at 9cfe5e3. Severity: high. Effort: M. audit-key: bug|mcp-server/src/utils/ssh-api.ts|EXEC_TIMEOUT_MS
Activity