diff --git a/packages/node/src/anr/index.ts b/packages/node/src/anr/index.ts index caa384b3928f..549b962d4b70 100644 --- a/packages/node/src/anr/index.ts +++ b/packages/node/src/anr/index.ts @@ -215,15 +215,21 @@ function handleChildProcess(options: Options): void { async function watchdogTimeout(): Promise { log('Watchdog timeout'); - const pauseAndCapture = await debuggerPause; - - if (pauseAndCapture) { - log('Pausing debugger to capture stack trace'); - pauseAndCapture(); - } else { - log('Capturing event'); - sendAnrEvent(); + + try { + const pauseAndCapture = await debuggerPause; + + if (pauseAndCapture) { + log('Pausing debugger to capture stack trace'); + pauseAndCapture(); + return; + } + } catch (_) { + // ignore } + + log('Capturing event'); + sendAnrEvent(); } const { poll } = watchdogTimer(createHrTimer, options.pollInterval, options.anrThreshold, watchdogTimeout); @@ -234,6 +240,10 @@ function handleChildProcess(options: Options): void { } poll(); }); + process.on('disconnect', () => { + // Parent process has exited. + process.exit(); + }); } /**