Skip to content

Prevent MediaPauseController queue hang on osascript timeout - #327

Open
toufiqfarhan0 wants to merge 1 commit into
AssemblyAI:mainfrom
toufiqfarhan0:fix/media-pause-osascript-timeout
Open

toufiqfarhan0 wants to merge 1 commit into
AssemblyAI:mainfrom
toufiqfarhan0:fix/media-pause-osascript-timeout

Conversation

@toufiqfarhan0

Copy link
Copy Markdown

Fixes #325

Problem

In MediaPauseController.runOSA, when an osascript process exceeded its 5-second timeout, process.terminate() was called to send SIGTERM, followed by an unbounded exited.wait():

if exited.wait(timeout: .now() + timeout) == .timedOut {
  process.terminate()
  exited.wait()
  logger.error("osascript timed out and was killed")
  return nil
}

If /usr/bin/osascript was wedged (e.g. hanging on synchronous AppleEvent IPC with a hung media player or modal dialog), it would not terminate upon receiving SIGTERM. Calling exited.wait() with no timeout blocked MediaPauseController.queue (a serial DispatchQueue) permanently. Consequently:

  1. Every subsequent pause() or resumePaused() invocation queued onto Self.queue blocked indefinitely.
  2. During app termination, restoreBeforeExit() queues onto Self.queue and waits up to exitBudget (2s), causing the app to hang on shutdown while failing to resume playback.

Fix

  1. Introduced killGraceTimeout = DispatchTimeInterval.milliseconds(500).
  2. Bound the post-termination wait. If the child process does not exit within 500 ms after SIGTERM, escalate to kill(process.processIdentifier, SIGKILL).
  3. Bound the follow-up wait to killGraceTimeout as well so MediaPauseController.queue is guaranteed never to block indefinitely.

Verification

  • scripts/check-invariants.sh passed (all 14 architectural invariants hold).
  • scripts/check-portability.sh passed.
  • Pre-existing line endings preserved (LF).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MediaPauseController.runOSA blocks serial queue indefinitely if osascript hangs after timeout

1 participant