Skip to content

start_recording in flight during shutdown leaves ffmpeg capturing after exit #285

Closed

Description

@TMHSDigital

Summary

shutdown() stops the sessions that exist when it runs and then exits. A start_recording that is between consent and store.create (1-2 s of awaits) is not seen, and its gdigrab/ddagrab ffmpeg keeps recording the screen with no owner.

Where

  • src/index.ts:91-118 (shutdown)
  • src/utils/lifecycle.ts:265-289 (stopAll reads ids once)
  • src/tools/startRecording.ts:210-481 (no isShuttingDown() check; child attached ~:437)
  • src/utils/jobs.ts:138 (edit jobs already refuse via jobsClosed)

Details

start_recording awaits confirmCapture, resolveLoopbackDevice, resolveEncoder and settleCapture before the session is registered. Edit jobs got a shutdown guard in #237; recordings did not. gdigrab ffmpeg does not stop when its stdin closes (see the #76 comment at src/index.ts:59-62).

Impact

A client that disconnects while a recording is starting leaves the screen being recorded until maxDurationSec (default 3600 s) or the next server start. Same privacy problem as #76 by a different path.

Steps to reproduce

  1. Call start_recording
  2. Close the client's stdin within ~1 s (during settleCapture)
  3. ffmpeg.exe is still running after node exits

Suggested fix

Check isShuttingDown() right after spawn and before returning; if set, quit/kill the child and throw. Or track in-flight starts in a set that shutdown awaits, like activeJobs.

Acceptance criteria

  • No ffmpeg capture survives a shutdown that races a start
  • Test covering shutdown during start (fake child is fine)

Related: #76, #237

Getting started

  • Relevant files: src/index.ts, src/utils/lifecycle.ts, src/tools/startRecording.ts, src/utils/jobs.ts
  • How to run tests: npm run build && npm test (also npm run typecheck and npm run lint)
  • Related docs: CONTRIBUTING.md, AGENTS.md

Filed by repo-audit/full-audit at f2fda28. Severity: medium. Effort: S. audit-key: bug|src/tools/startRecording.ts|shutdown-race

Activity

  1. added
    bug
    on Nov 9, 2026
  2. TMHSDigital commented on Nov 10, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 0d96cd5: start_recording now registers itself as in flight (beginStart in src/context.ts) and is refused once shutdown begins; shutdown() waits up to 10 s for in-flight starts before stopAll, so their sessions are registered and stopped. Verified with unit tests in src/tests/startGuard.test.ts plus build/typecheck/lint/server tests.

  3. added a commit that references this issue on Nov 10, 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

    bugpriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions