This commit is contained in:
Chris Wanstrath 2026-02-17 14:47:47 -08:00
parent b538626baa
commit c5672e57bd

View File

@ -490,14 +490,29 @@ function handleHealthCheckFailure(app: App) {
}
async function killStaleProcesses() {
const result = Bun.spawnSync(['lsof', '-ti', `:${MIN_PORT - 1}-${MAX_PORT}`])
const output = result.stdout.toString().trim()
if (!output) return
const pids = new Set<number>()
const pids = output.split('\n').map(Number).filter(pid => pid && pid !== process.pid)
if (pids.length === 0) return
// Find processes listening on our port range
const lsof = Bun.spawnSync(['lsof', '-ti', `:${MIN_PORT - 1}-${MAX_PORT}`])
const lsofOutput = lsof.stdout.toString().trim()
if (lsofOutput) {
for (const pid of lsofOutput.split('\n').map(Number)) {
if (pid && pid !== process.pid) pids.add(pid)
}
}
hostLog(`Found ${pids.length} stale process(es) on ports ${MIN_PORT - 1}-${MAX_PORT}`)
// Find orphaned "bun run toes" child app processes
const pgrep = Bun.spawnSync(['pgrep', '-f', 'bun run toes'])
const pgrepOutput = pgrep.stdout.toString().trim()
if (pgrepOutput) {
for (const pid of pgrepOutput.split('\n').map(Number)) {
if (pid && pid !== process.pid) pids.add(pid)
}
}
if (pids.size === 0) return
hostLog(`Found ${pids.size} stale process(es)`)
for (const pid of pids) {
try {
process.kill(pid, 'SIGKILL')