perf(comment-checker): add hard process reap and global semaphore to prevent CPU runaway

This commit is contained in:
YeonGyu-Kim
2026-02-13 11:49:29 +09:00
parent 9304070e0d
commit 9c43e10055
3 changed files with 264 additions and 93 deletions
+16 -4
View File
@@ -180,14 +180,26 @@ export async function runCommentChecker(input: HookInput, cliPath?: string, cust
let timeoutId: ReturnType<typeof setTimeout> | null = null
const timeoutPromise = new Promise<"timeout">(resolve => {
timeoutId = setTimeout(() => {
timeoutId = setTimeout(async () => {
didTimeout = true
debugLog("comment-checker timed out after 30s; killing process")
debugLog("comment-checker timed out after 30s; sending SIGTERM")
try {
proc.kill()
proc.kill("SIGTERM")
} catch (err) {
debugLog("failed to kill comment-checker process:", err)
debugLog("failed to SIGTERM:", err)
}
const graceTimer = setTimeout(() => {
try {
proc.kill("SIGKILL")
debugLog("sent SIGKILL after grace period")
} catch {
}
}, 1000)
try {
await proc.exited
} catch {
}
clearTimeout(graceTimer)
resolve("timeout")
}, 30_000)
})