Skip to content

Server crashes or orphans a recording when a session-registry write fails inside a recording event handler #207

Closed

Description

@TMHSDigital

Why it matters

A full disk or a briefly locked sessions.json (antivirus, OneDrive) can crash the whole MCP server, or leave an ffmpeg capture running that nothing can stop.

Evidence

  • src/tools/startRecording.ts:288-314: the ffmpeg child exit handler calls store.update, which calls persist(). persist() throws on writeFileSync errors (ENOSPC) and when renameWithRetry gives up after about 1 s of EPERM/EBUSY (src/utils/sessions.ts:195, 327-328). An exception in an EventEmitter handler is uncaught.
  • src/utils/events.ts:329 uses void done.finally(...). Its catch path at startRecording.ts:276 also calls store.update, so a rejection there is unhandled.
  • The process has no uncaughtException or unhandledRejection handler. When the server dies, the shutdown stopAll never runs and other recordings keep capturing until their cap.
  • startRecording.ts:260-262: store.create(record) runs after ffmpeg and the input logger have started. If it throws, the tool returns an error with no session id and no attachChild, and capture continues for up to maxDurationSec (default 1 h). Neither stop_recording nor shutdown can reach it.

Suggested approach

  • Wrap registry writes in event handlers in try/catch and log to stderr.
  • Add .catch on the finalizer chain.
  • Register the child for shutdown before writing the registry, and kill the child if store.create fails.
  • Add process-level handlers that run stopAll and log, so a crash never leaves captures running.

Done when

  • Unit tests: an injected persist failure in the exit handler does not crash the process, and a store.create failure kills the spawned child.

Activity

  1. added
    bug
    effort: small
    impact: medium
    on Oct 25, 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

    bugeffort: smallimpact: mediumpriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions