Skip to content

Commit

Permalink
fix(node): Handle inspector already open (#10025)
Browse files Browse the repository at this point in the history
If the inspector is already running, then ANR should be able to (re)use
that, instead of opening it itself.
  • Loading branch information
joshkel authored Jan 2, 2024
1 parent d2e0465 commit 1cd771a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
});
});

test('With --inspect', done => {
expect.assertions(7);

const testScriptPath = path.resolve(__dirname, 'basic.js');

childProcess.exec(`node --inspect ${testScriptPath}`, { encoding: 'utf8' }, (_, stdout) => {
const [event] = parseJsonLines<[Event]>(stdout, 1);

expect(event.exception?.values?.[0].mechanism).toEqual({ type: 'ANR' });
expect(event.exception?.values?.[0].type).toEqual('ApplicationNotResponding');
expect(event.exception?.values?.[0].value).toEqual('Application Not Responding for at least 200 ms');
expect(event.exception?.values?.[0].stacktrace?.frames?.length).toBeGreaterThan(4);

expect(event.exception?.values?.[0].stacktrace?.frames?.[2].function).toEqual('?');
expect(event.exception?.values?.[0].stacktrace?.frames?.[3].function).toEqual('longWork');

done();
});
});

test('With session', done => {
expect.assertions(9);

Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/integrations/anr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class Anr implements Integration {
if (options.captureStackTrace) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const inspector: InspectorApi = require('inspector');
inspector.open(0);
if (!inspector.url()) {
inspector.open(0);
}
}

const { Worker } = getWorkerThreads();
Expand Down

0 comments on commit 1cd771a

Please sign in to comment.