Skip to content

πŸŽ₯ Make videos programmatically with React

fix(renderer): SIGKILL Chrome/compositor when Node parent dies on Linux

Jonny Burger0c7cf069dedb
diff --git a/bun.lock b/bun.lock
index 5d25ebc155..5f4e9930cb 100644
--- a/bun.lock
+++ b/bun.lock
@@ -409,6 +409,16 @@
"name": "@remotion/discord-poster",
"version": "4.0.457",
},
+ "packages/docker-repro-minimal": {
+ "name": "@remotion/docker-repro-minimal",
+ "version": "4.0.457",
+ "dependencies": {
+ "@remotion/cli": "workspace:*",
+ "react": "catalog:",
+ "react-dom": "catalog:",
+ "remotion": "workspace:*",
+ },
+ },
"packages/docs": {
"name": "docs",
"version": "4.0.457",
@@ -3822,6 +3832,8 @@
"@remotion/discord-poster": ["@remotion/discord-poster@workspace:packages/discord-poster"],
+ "@remotion/docker-repro-minimal": ["@remotion/docker-repro-minimal@workspace:packages/docker-repro-minimal"],
+
"@remotion/docusaurus-plugin": ["@remotion/docusaurus-plugin@workspace:packages/docusaurus-plugin"],
"@remotion/effects": ["@remotion/effects@workspace:packages/effects"],
diff --git a/packages/docker-repro-minimal/package.json b/packages/docker-repro-minimal/package.json
new file mode 100644
index 0000000000..932818c107
--- /dev/null
+++ b/packages/docker-repro-minimal/package.json
@@ -0,0 +1,20 @@
+{
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion/tree/main/packages/docker-repro-minimal"
+ },
+ "name": "@remotion/docker-repro-minimal",
+ "private": true,
+ "version": "4.0.457",
+ "license": "SEE LICENSE IN LICENSE.md",
+ "author": "Remotion",
+ "description": "Minimal Remotion project for Linux/Docker Chrome process repros",
+ "scripts": {
+ "bundle": "remotion bundle src/index.ts --out-dir ../dockerfiles/bundle"
+ },
+ "dependencies": {
+ "remotion": "workspace:*",
+ "@remotion/cli": "workspace:*",
+ "react": "catalog:",
+ "react-dom": "catalog:"
+ }
+}
diff --git a/packages/docker-repro-minimal/remotion.config.ts b/packages/docker-repro-minimal/remotion.config.ts
new file mode 100644
index 0000000000..ad33cc6441
--- /dev/null
+++ b/packages/docker-repro-minimal/remotion.config.ts
@@ -0,0 +1,3 @@
+import {Config} from '@remotion/cli/config';
+
+Config.setOverwriteOutput(true);
diff --git a/packages/docker-repro-minimal/src/Minimal.tsx b/packages/docker-repro-minimal/src/Minimal.tsx
new file mode 100644
index 0000000000..91848ecd37
--- /dev/null
+++ b/packages/docker-repro-minimal/src/Minimal.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+export const Minimal: React.FC = () => {
+ return (
+ <AbsoluteFill style={{backgroundColor: '#111', justifyContent: 'center', alignItems: 'center'}}>
+ <div style={{color: '#fff', fontFamily: 'sans-serif', fontSize: 24}}>minimal repro</div>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docker-repro-minimal/src/ReproRoot.tsx b/packages/docker-repro-minimal/src/ReproRoot.tsx
new file mode 100644
index 0000000000..8a9e932cae
--- /dev/null
+++ b/packages/docker-repro-minimal/src/ReproRoot.tsx
@@ -0,0 +1,16 @@
+import React from 'react';
+import {Composition} from 'remotion';
+import {Minimal} from './Minimal';
+
+export const ReproRoot: React.FC = () => {
+ return (
+ <Composition
+ id="minimal"
+ component={Minimal}
+ fps={30}
+ width={640}
+ height={360}
+ durationInFrames={60}
+ />
+ );
+};
diff --git a/packages/docker-repro-minimal/src/index.ts b/packages/docker-repro-minimal/src/index.ts
new file mode 100644
index 0000000000..c4174f7982
--- /dev/null
+++ b/packages/docker-repro-minimal/src/index.ts
@@ -0,0 +1,4 @@
+import {registerRoot} from 'remotion';
+import {ReproRoot} from './ReproRoot';
+
+registerRoot(ReproRoot);
diff --git a/packages/docker-repro-minimal/tsconfig.json b/packages/docker-repro-minimal/tsconfig.json
new file mode 100644
index 0000000000..d861cf1a48
--- /dev/null
+++ b/packages/docker-repro-minimal/tsconfig.json
@@ -0,0 +1,12 @@
+{
+ "extends": "../tsconfig.settings.json",
+ "compilerOptions": {
+ "rootDir": "./src",
+ "outDir": "./dist",
+ "jsx": "react-jsx",
+ "skipLibCheck": true,
+ "allowSyntheticDefaultImports": true
+ },
+ "include": ["src"],
+ "references": [{"path": "../core"}, {"path": "../cli"}]
+}
diff --git a/packages/dockerfiles/Dockerfile.repro-chrome-linux b/packages/dockerfiles/Dockerfile.repro-chrome-linux
new file mode 100644
index 0000000000..6067217bad
--- /dev/null
+++ b/packages/dockerfiles/Dockerfile.repro-chrome-linux
@@ -0,0 +1,45 @@
+# Repro image for Linux Chrome/headless process leaks (#7065, #7207).
+# Differs from Dockerfile.ubuntu24: render + ps run in one container session (ENTRYPOINT),
+# not split across RUN layers (which would tear down Chrome between steps).
+FROM ubuntu:24.04
+
+RUN apt-get update
+RUN apt-get install git curl make unzip procps -y
+RUN curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s 20
+RUN curl -fsSL https://bun.com/install | bash && ln -s /root/.bun/bin/bun /usr/local/bin/bun
+WORKDIR /usr/app
+
+COPY tarballs/ /usr/app/tarballs/
+COPY local-cli-package.json /usr/app/package.json
+RUN bun install
+ENV PATH="/usr/app/node_modules/.bin:$PATH"
+
+RUN apt install -y \
+ libnss3 \
+ libdbus-1-3 \
+ libatk1.0-0 \
+ libasound2t64 \
+ libxrandr2 \
+ libxkbcommon-dev \
+ libxfixes3 \
+ libxcomposite1 \
+ libxdamage1 \
+ libgbm-dev \
+ libcups2 \
+ libcairo2 \
+ libpango-1.0-0 \
+ libatk-bridge2.0-0
+
+COPY ensure-browser.mjs .
+COPY ensure.mjs .
+RUN node ensure.mjs
+
+COPY bundle/ /usr/app/bundle/
+
+RUN remotion compositions /usr/app/bundle
+
+COPY repro-chrome-after-render.sh /usr/app/repro-chrome-after-render.sh
+COPY repro-sigkill-parent.sh /usr/app/repro-sigkill-parent.sh
+RUN chmod +x /usr/app/repro-chrome-after-render.sh /usr/app/repro-sigkill-parent.sh
+
+ENTRYPOINT ["/usr/app/repro-chrome-after-render.sh"]
diff --git a/packages/dockerfiles/build-repro-chrome-image.sh b/packages/dockerfiles/build-repro-chrome-image.sh
new file mode 100755
index 0000000000..6a4cdd2e8c
--- /dev/null
+++ b/packages/dockerfiles/build-repro-chrome-image.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+# Prepare tarballs + bundle (same as run.sh front matter), then build the repro image.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
+cd "${SCRIPT_DIR}"
+
+echo "== Workspace build (ensure-browser bundle + bundle CLI need compiled packages) =="
+cd "${REPO_ROOT}"
+# CLI pulls bundler/example deps; renderer/core needed for ensure-browser.mjs bundle.
+bunx turbo run make --filter=@remotion/cli --filter=remotion --filter=@remotion/renderer --no-update-notifier
+cd "${SCRIPT_DIR}"
+
+echo "== Building browser downloader + ensure-browser.mjs =="
+cd ../renderer
+bun build-browser-downloader.ts
+cp ensure-browser.mjs ../dockerfiles/ensure-browser.mjs
+cd ../dockerfiles
+
+echo "== Packing local @remotion/cli =="
+bun pack-cli.ts
+
+echo "== Building minimal repro bundle (packages/docker-repro-minimal) =="
+cd ../docker-repro-minimal
+bunx remotion bundle src/index.ts --out-dir ../dockerfiles/bundle
+cd ../dockerfiles
+
+PLATFORM_FLAG=()
+if [[ "${BUILD_PLATFORM:-}" != "" ]]; then
+ PLATFORM_FLAG=(--platform "${BUILD_PLATFORM}")
+fi
+
+echo "== docker build Dockerfile.repro-chrome-linux =="
+docker build "${PLATFORM_FLAG[@]}" --file Dockerfile.repro-chrome-linux -t remotion-repro-chrome-linux .
+
+echo ""
+echo "Done. Run (add --init if you want PID 1 to reap zombies like a real init):"
+echo " docker run --rm --init remotion-repro-chrome-linux"
+echo ""
+echo "Optional (#7207-style kill parent):"
+echo " docker run --rm --init --entrypoint /usr/app/repro-sigkill-parent.sh remotion-repro-chrome-linux"
diff --git a/packages/dockerfiles/repro-chrome-after-render.sh b/packages/dockerfiles/repro-chrome-after-render.sh
new file mode 100755
index 0000000000..ebad8fe1bc
--- /dev/null
+++ b/packages/dockerfiles/repro-chrome-after-render.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+# Repro helper for GitHub issues #7065 / #7207: inspect Chrome-related processes
+# immediately after a render finishes (same shell session β€” required to see leaks).
+set -euo pipefail
+
+cd /usr/app
+export PATH="/usr/app/node_modules/.bin:${PATH}"
+
+OUT_MP4="${OUT_MP4:-/tmp/repro-out.mp4}"
+COMPOSITION_ID="${COMPOSITION_ID:-minimal}"
+
+echo "=== Before render ==="
+ps -eo pid,ppid,stat,comm | head -25
+
+echo ""
+echo "=== Running render (${COMPOSITION_ID}) β†’ ${OUT_MP4} ==="
+remotion render /usr/app/bundle "${COMPOSITION_ID}" "${OUT_MP4}" --log=verbose
+
+echo ""
+echo "=== Immediately after render (Chrome / headless / zombies) ==="
+# Match issue reports: chrome-headless-shell, chrome-headless, etc.
+ps -efww | grep -E 'chrome|Chrome|CHROMIUM|headless' | grep -v grep || true
+pgrep -af 'chrome-headless' || echo "(pgrep: no chrome-headless)"
+
+echo ""
+echo "=== Rows with PPID 1 or zombie state (Z) ==="
+ps -eo pid,ppid,stat,args | awk 'NR==1 || $2==1 || $3 ~ /^Z/ {print}'
+
+echo ""
+echo "=== Full ps (for manual inspection) ==="
+ps auxww
+
+echo ""
+echo "Render output file:"
+ls -la "${OUT_MP4}"
diff --git a/packages/dockerfiles/repro-sigkill-parent.sh b/packages/dockerfiles/repro-sigkill-parent.sh
new file mode 100755
index 0000000000..bde15f856d
--- /dev/null
+++ b/packages/dockerfiles/repro-sigkill-parent.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+# Repro for #7207: force-kill the Node parent during render; chrome-headless-shell
+# should survive with PPID=1 if not tied to parent lifetime.
+# Run inside the repro Docker image (same deps as Dockerfile.repro-chrome-linux).
+set -euo pipefail
+
+cd /usr/app
+export PATH="/usr/app/node_modules/.bin:${PATH}"
+
+OUT_MP4="${OUT_MP4:-/tmp/repro-sigkill-out.mp4}"
+COMPOSITION_ID="${COMPOSITION_ID:-minimal}"
+
+echo "=== Spawning render in background (${COMPOSITION_ID}) ==="
+remotion render /usr/app/bundle "${COMPOSITION_ID}" "${OUT_MP4}" --log=verbose &
+RENDER_PID=$!
+
+echo "Render PID: ${RENDER_PID}"
+# Minimal comp (~2s @ 30fps); wait until Chrome is usually up.
+sleep 2
+
+echo "=== Sending SIGKILL to Node render parent ==="
+kill -9 "${RENDER_PID}" || true
+
+sleep 2
+
+echo "=== chrome-headless-shell still alive? (expect orphans if bug reproduces) ==="
+ps -efww | grep -E 'chrome|Chrome|headless' | grep -v grep || echo "(none)"
+
+echo ""
+echo "=== Processes with PPID 1 ==="
+ps -eo pid,ppid,stat,args | awk 'NR==1 || $2==1 {print}'
diff --git a/packages/renderer/src/browser/BrowserRunner.ts b/packages/renderer/src/browser/BrowserRunner.ts
index c5a6761735..5844836798 100644
--- a/packages/renderer/src/browser/BrowserRunner.ts
+++ b/packages/renderer/src/browser/BrowserRunner.ts
@@ -17,6 +17,7 @@
import * as childProcess from 'node:child_process';
import {join} from 'node:path';
import {deleteDirectory} from '../delete-directory';
+import {wrapExecutableWithSetprivIfAvailable} from '../linux/wrap-with-setpriv';
import type {LogLevel} from '../log-level';
import {isEqualOrBelowLogLevel} from '../log-level';
import {Log} from '../logger';
@@ -61,7 +62,18 @@ export const makeBrowserRunner = async ({
? ['ignore', 'pipe', 'pipe']
: ['pipe', 'pipe', 'pipe'];
- const proc = childProcess.spawn(executablePath, processArguments, {
+ const launch = wrapExecutableWithSetprivIfAvailable({
+ executablePath,
+ args: processArguments,
+ });
+ if (launch.executablePath !== executablePath) {
+ Log.verbose(
+ {indent, logLevel},
+ 'Using setpriv --pdeathsig SIGKILL so the browser is killed if the Node parent process dies (Linux).',
+ );
+ }
+
+ const proc = childProcess.spawn(launch.executablePath, launch.args, {
// On non-windows platforms, `detached: true` makes child process a
// leader of a new process group, making it possible to kill child
// process tree with `.kill(-pid)` command. @see
diff --git a/packages/renderer/src/compositor/compositor.ts b/packages/renderer/src/compositor/compositor.ts
index 3730229a30..dc41cf02e1 100644
--- a/packages/renderer/src/compositor/compositor.ts
+++ b/packages/renderer/src/compositor/compositor.ts
@@ -1,6 +1,7 @@
import {spawn} from 'node:child_process';
import path from 'node:path';
import {makeStreamer} from '@remotion/streaming';
+import {wrapExecutableWithSetprivIfAvailable} from '../linux/wrap-with-setpriv';
import type {LogLevel} from '../log-level';
import {isEqualOrBelowLogLevel} from '../log-level';
import {Log} from '../logger';
@@ -98,7 +99,19 @@ export const startCompositor = <T extends keyof CompositorCommand>({
const cwd = path.dirname(bin);
- const child = spawn(bin, [JSON.stringify(fullCommand)], {
+ const jsonArg = JSON.stringify(fullCommand);
+ const launch = wrapExecutableWithSetprivIfAvailable({
+ executablePath: bin,
+ args: [jsonArg],
+ });
+ if (launch.executablePath !== bin) {
+ Log.verbose(
+ {indent, logLevel, tag: 'compositor'},
+ 'Using setpriv --pdeathsig SIGKILL so the compositor is killed if the Node parent process dies (Linux).',
+ );
+ }
+
+ const child = spawn(launch.executablePath, launch.args, {
cwd,
env:
process.platform === 'darwin'
diff --git a/packages/renderer/src/linux/wrap-with-setpriv.ts b/packages/renderer/src/linux/wrap-with-setpriv.ts
new file mode 100644
index 0000000000..f04682c18b
--- /dev/null
+++ b/packages/renderer/src/linux/wrap-with-setpriv.ts
@@ -0,0 +1,51 @@
+import {execSync} from 'node:child_process';
+
+let cachedSetprivPath: string | null | undefined;
+
+/**
+ * When the Node parent dies abruptly (SIGKILL, kernel OOM, etc.), child processes
+ * are reparented to init and may keep running. On Linux, `setpriv(1)` uses
+ * prctl(PR_SET_PDEATHSIG) so the child receives SIGKILL when its parent dies.
+ *
+ * @see https://github.com/remotion-dev/remotion/issues/7207
+ */
+export const resolveSetprivPathOnLinux = (): string | null => {
+ if (cachedSetprivPath !== undefined) {
+ return cachedSetprivPath;
+ }
+
+ if (process.platform !== 'linux') {
+ cachedSetprivPath = null;
+ return null;
+ }
+
+ try {
+ const path = execSync('command -v setpriv 2>/dev/null', {
+ encoding: 'utf8',
+ stdio: ['ignore', 'pipe', 'ignore'],
+ }).trim();
+ cachedSetprivPath = path ? path : null;
+ } catch {
+ cachedSetprivPath = null;
+ }
+
+ return cachedSetprivPath;
+};
+
+export const wrapExecutableWithSetprivIfAvailable = ({
+ executablePath,
+ args,
+}: {
+ executablePath: string;
+ args: string[];
+}): {executablePath: string; args: string[]} => {
+ const setpriv = resolveSetprivPathOnLinux();
+ if (!setpriv) {
+ return {executablePath, args};
+ }
+
+ return {
+ executablePath: setpriv,
+ args: ['--pdeathsig', 'SIGKILL', executablePath, ...args],
+ };
+};
diff --git a/packages/renderer/src/test/wrap-with-setpriv.test.ts b/packages/renderer/src/test/wrap-with-setpriv.test.ts
new file mode 100644
index 0000000000..194365f13f
--- /dev/null
+++ b/packages/renderer/src/test/wrap-with-setpriv.test.ts
@@ -0,0 +1,30 @@
+import {describe, expect, test} from 'bun:test';
+import {
+ resolveSetprivPathOnLinux,
+ wrapExecutableWithSetprivIfAvailable,
+} from '../linux/wrap-with-setpriv';
+
+describe('wrap-with-setpriv', () => {
+ test('returns executable + args array', () => {
+ const r = wrapExecutableWithSetprivIfAvailable({
+ executablePath: '/bin/sh',
+ args: ['-c', 'true'],
+ });
+ expect(typeof r.executablePath).toBe('string');
+ expect(Array.isArray(r.args)).toBe(true);
+ });
+
+ test('on non-linux, passes through unchanged', () => {
+ if (process.platform === 'linux') {
+ return;
+ }
+
+ const r = wrapExecutableWithSetprivIfAvailable({
+ executablePath: '/bin/sh',
+ args: ['-c', 'true'],
+ });
+ expect(r.executablePath).toBe('/bin/sh');
+ expect(r.args).toEqual(['-c', 'true']);
+ expect(resolveSetprivPathOnLinux()).toBe(null);
+ });
+});