: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(dev): reap orphaned vite subtree when start-frontend exits (#61964)
Phil Haack208d28a75f9a
diff --git a/bin/start-frontend b/bin/start-frontendindex b51c22916cef..b70f93d7dbaf 100755--- a/bin/start-frontend+++ b/bin/start-frontend@@ -11,5 +11,45 @@ export DEBUG=0# Auto-accept corepack download prompts (hangs in non-interactive contexts)export COREPACK_ENABLE_DOWNLOAD_PROMPT=0+# Recursively collect every descendant PID of the given pid, deepest first.+# turbo's launcher re-parents the vite subtree into its own process group, so the+# sibling `kill -- -$$` process-group idiom (start-go-service/start-rust-service)+# misses it — we have to walk the tree by PID instead.+collect_descendants() {+ local parent=$1 child+ for child in $(pgrep -P "$parent" 2>/dev/null); do+ collect_descendants "$child"+ echo "$child"+ done+}++# When the process manager stops us (q / SIGTERM / SIGINT) bash would otherwise+# exit without forwarding the signal to turbo, orphaning the whole+# turbo → concurrently → vite (+ toolbar esbuild) subtree — leaving vite+# squatting port 8234 across sessions. Tear the entire descendant tree down.+shutdown() {+ trap - INT TERM EXIT+ local pids+ pids=$(collect_descendants $$)+ # shellcheck disable=SC2086+ kill -TERM $pids 2>/dev/null || true+ # Give the tree a moment to exit gracefully, then force-kill survivors.+ for _ in 1 2 3 4 5 6 7 8 9 10; do+ pids=$(collect_descendants $$)+ [ -z "$pids" ] && break+ sleep 0.3+ done+ # shellcheck disable=SC2086+ kill -KILL $pids 2>/dev/null || true+}+trap shutdown INT TERM EXIT+pnpm --filter=@posthog/frontend... install-bin/turbo --filter=@posthog/frontend start-vite++# Run turbo in the background and wait on it so the trap above can fire while+# turbo is running (a foreground child would keep bash blocked in turbo's own+# wait, delaying signal handling). `wait` returns when turbo exits or when a+# trapped signal interrupts it, at which point shutdown() reaps the subtree.+bin/turbo --filter=@posthog/frontend start-vite &+turbo_pid=$!+wait "$turbo_pid"