Skip to content

Fixed 30s exec timeout breaks long-running tools (apt, restic, compose pull, trivy) #86

Closed

Description

@TMHSDigital

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

  1. Call homelab_aptUpdate {upgrade: true} on a Pi with pending updates, or homelab_containerScan {} with several images.
  2. 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=noninteractive and -o Dpkg::Options::=--force-confold for upgrades.

Acceptance criteria

  • execSSH accepts 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

  1. added
    bug
    help wanted
    severity: high
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedseverity: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions