Skip to content

Commit 205c1c9

Browse files
authored
fix(node): Improve error handling and shutdown handling for ANR (#9548)
If communicating via debugger to generate a stack trace fails, then fall back to a regular event, instead of throwing an uncaught exception. If the parent process exits, exit the ANR child.
1 parent 332f8e7 commit 205c1c9

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

packages/node/src/anr/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,21 @@ function handleChildProcess(options: Options): void {
215215

216216
async function watchdogTimeout(): Promise<void> {
217217
log('Watchdog timeout');
218-
const pauseAndCapture = await debuggerPause;
219-
220-
if (pauseAndCapture) {
221-
log('Pausing debugger to capture stack trace');
222-
pauseAndCapture();
223-
} else {
224-
log('Capturing event');
225-
sendAnrEvent();
218+
219+
try {
220+
const pauseAndCapture = await debuggerPause;
221+
222+
if (pauseAndCapture) {
223+
log('Pausing debugger to capture stack trace');
224+
pauseAndCapture();
225+
return;
226+
}
227+
} catch (_) {
228+
// ignore
226229
}
230+
231+
log('Capturing event');
232+
sendAnrEvent();
227233
}
228234

229235
const { poll } = watchdogTimer(createHrTimer, options.pollInterval, options.anrThreshold, watchdogTimeout);
@@ -234,6 +240,10 @@ function handleChildProcess(options: Options): void {
234240
}
235241
poll();
236242
});
243+
process.on('disconnect', () => {
244+
// Parent process has exited.
245+
process.exit();
246+
});
237247
}
238248

239249
/**

0 commit comments

Comments
 (0)