Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay): let in-flight renders finish on rasterizer shutdown (#126805)

Daniel5b91b629b34e
diff --git a/nodejs/src/session-replay/recording-rasterizer/config.ts b/nodejs/src/session-replay/recording-rasterizer/config.ts
index 14e276ab678d..bcd6f5cab4b9 100644
--- a/nodejs/src/session-replay/recording-rasterizer/config.ts
+++ b/nodejs/src/session-replay/recording-rasterizer/config.ts
@@ -34,6 +34,10 @@ export const config = {
tunerTargetMemoryUsage: parseFraction(process.env.TUNER_TARGET_MEMORY_USAGE, 0.7),
tunerTargetCpuUsage: parseFraction(process.env.TUNER_TARGET_CPU_USAGE, 0.9),
tunerRampThrottleMs: parsePositiveInt(process.env.TUNER_RAMP_THROTTLE_MS, 10_000),
+ // On SIGTERM (deploy, scale-down, node replacement) the worker waits this long for in-flight renders before
+ // the SDK cancels them. The SDK default is 0, which cancels every running render at once. Keep it below the
+ // pod's terminationGracePeriodSeconds (1800s in prod) so the process still exits before it is killed.
+ shutdownGraceTimeMs: parsePositiveInt(process.env.SHUTDOWN_GRACE_TIME_MS, 25 * 60 * 1000),
browserRecycleAfter: parsePositiveInt(process.env.BROWSER_RECYCLE_AFTER, 100),
// Browsers held warm beyond this are closed on release: each idle Chromium pins 100-250MB RSS,
// and a pod that once ran at full concurrency would otherwise keep that footprint forever.
diff --git a/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts b/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts
index fa95545886b6..a762efead2fd 100644
--- a/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts
+++ b/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts
@@ -156,6 +156,8 @@ async function main(): Promise<void> {
// parent workflow on short recordings. 2s matches the summary polling cadence.
defaultHeartbeatThrottleInterval: '2s',
maxHeartbeatThrottleInterval: '5s',
+ // Let in-flight renders finish after shutdown() instead of cancelling them right away (SDK default 0).
+ shutdownGraceTime: config.shutdownGraceTimeMs,
})
metricsServer.setReady(true)