Service capture cleanup in packaged watchdog smoke

This commit is contained in:
Brennan Benson
2026-11-11 14:24:54 -08:00
parent 2e78872b54
commit 69e53a2dab
@@ -85,14 +85,13 @@ async function runInternal() {
const tempRoot = mkdtempSync(join(tmpdir(), 'orca-packaged-watchdog-smoke-'))
const markerPath = join(tempRoot, 'main-thread-hang.json')
const entryPath = join(appAsar, 'out', 'main', 'main-thread-hang-watchdog-entry.js')
let worker
try {
await app.whenReady()
if (!existsSync(entryPath)) {
throw new Error(`Packaged watchdog entry is missing from app.asar: ${entryPath}`)
}
const workerError = { current: null }
worker = new Worker(entryPath, {
const worker = new Worker(entryPath, {
workerData: {
parentPid: process.pid,
markerPath,
@@ -103,15 +102,22 @@ async function runInternal() {
worker.once('error', (error) => {
workerError.current = error
})
worker.on('message', (message) => {
if (
message?.type === 'capture-drain' &&
typeof message.token === 'string' &&
message.token.length <= 80
) {
setImmediate(() => worker.postMessage({ type: 'capture-drain-ack', token: message.token }))
}
})
await waitForMarker(markerPath, (marker) => marker?.selfRecovered === false, workerError)
worker.postMessage({ type: 'heartbeat' })
await waitForMarker(markerPath, (marker) => marker?.selfRecovered === true, workerError)
worker.postMessage({ type: 'shutdown' })
await waitForExit(worker, workerError)
worker = undefined
console.log(SUCCESS_LINE)
} finally {
await worker?.terminate()
rmSync(tempRoot, { recursive: true, force: true })
}
}