Skip to content

Capture scheduler hangs indefinitely when capture operation stalls #5

@panoptican

Description

@panoptican

Type: Bug Report

Description:
The capture scheduler uses a lock to prevent concurrent capture operations. However, if a capture operation hangs indefinitely (e.g., due to system permission issues, display driver problems, or OCR processing stalls), the lock is never released, causing all subsequent scheduled and manual captures to be skipped silently.

Steps to Reproduce:

  1. Start screencap with the scheduler running
  2. Trigger a condition where the capture pipeline stalls (e.g., disconnect external display during capture)
  3. Observe that all subsequent captures are skipped with "Capture already in progress"

Expected Behavior:
The scheduler should detect stale locks and recover automatically, continuing to capture after a reasonable timeout.

Proposed Solution:
Add a timeout mechanism (e.g., 60 seconds) that force-releases stale capture locks:

const CAPTURE_TIMEOUT_MS = 60 * 1000; // 60 seconds max
let captureLockAcquiredAt: number | null = null;

function checkAndReleaseStaleLock(): boolean {
  if (captureLock && captureLockAcquiredAt) {
    const heldFor = Date.now() - captureLockAcquiredAt;
    if (heldFor > CAPTURE_TIMEOUT_MS) {
      logger.warn("Capture lock held too long, force releasing", {
        heldForMs: heldFor,
        timeoutMs: CAPTURE_TIMEOUT_MS,
      });
      captureLock = null;
      captureLockAcquiredAt = null;
      return true;
    }
  }
  return false;
}

Environment:

  • macOS 14.x
  • screencap v1.17.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions