Skip to content

Studio (macOS): prewarmed osascript file picker is orphaned on SIGTERM/SIGKILL and spins at high CPU #13669

Backlog

Description

@BelarDzik

Bug Report 🐛

On macOS, Studio starts a "prewarmed" native file picker (osascript -l JavaScript, the RemotionFilePickerPositioner script in @remotion/studio-server/dist/native-file-picker.js) on every HTML page load. Two problems together left orphaned osascript processes at ~45–60% CPU each, running for hours after Studio had stopped (six of them, from automated Studio checks):

  1. The prewarmed osascript outlives Studio when Studio gets SIGTERM or SIGKILL.
    • The prewarm is triggered in routes.js (handleFallback, ~line 118) for any loopback GET whose Accept contains text/html. A headless browser loading the page is enough, with no click on any picker.
    • The child is spawned non-detached with piped stdio, and then unref'd (native-file-picker.js lines ~103–151).
    • Cleanup is only process.once('exit', () => child.kill()) and closeNativeFilePicker() on server close. The CLI handles only SIGINT (studio-shortcuts.js), so kill <pid> (SIGTERM) or SIGKILL skips both, and the child is reparented to PID 1.
  2. On this machine, the script never gets past ObjC.registerSubclass. sample shows 730 of 731 samples in ObjC.registerSubclass → ffi_closure_alloc → dlmmap (libffi looping on mkostemp/mmap/unlink). So the child never reaches its stdin read, and it spins even while Studio is alive. A minimal standalone JXA script with only one ObjC.registerSubclass call (one method) spins the same way at ~55% CPU, so the spin itself looks like an OS/JXA issue. But Studio starts it with no timeout on every page load, and nothing ends it.

Reproduction

npx remotion studio src/index.ts --no-open --port=3500 &
STUDIO=$!
sleep 10
curl -s -H 'Accept: text/html' http://localhost:3500/ > /dev/null
sleep 5
pgrep -fl RemotionFilePickerPositioner   # one osascript, already at high CPU
kill $STUDIO                              # SIGTERM
sleep 2
ps -o pid,ppid,%cpu,command -p $(pgrep -f RemotionFilePickerPositioner)   # PPID 1, still spinning

Results by how Studio is stopped:

stop prewarmed osascript
SIGTERM to the Studio pid orphaned (PPID 1), 47–60% CPU
SIGKILL to the Studio pid orphaned (PPID 1), 62% CPU
SIGINT to the Studio pid gone
SIGTERM to the process group gone

A request without an Accept: text/html header spawns nothing.

Environment

  • Remotion / @remotion/studio-server 4.0.547. The file first appears in 4.0.542 (@remotion/studio: Add OpenTimelineIO import #12580). native-file-picker.ts on main is unchanged.
  • macOS 26.7.3, x86_64. Node v24.16.0.
  • Not run over SSH (with SSH_CONNECTION set, the native picker is disabled, so there is no prewarm).

Suggestions

  • Start the picker on demand, not on every page load. Or give the prewarmed child a timeout.
  • Handle SIGTERM and SIGHUP like SIGINT. Or spawn the child so that it dies with the parent (for example, a watchdog that exits on stdin EOF before registerSubclass).
  • Add an option or env flag to turn off the native picker.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions