Skip to content

Script won't exit with ANR and captureStackTrace active #10022

Closed

Description

@joshkel

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.91.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

 Sentry.init({
    dsn: process.env.SENTRY_DSN,
    integrations: [new Sentry.Integrations.Anr({captureStackTrace: true})],
  });

Steps to Reproduce

import * as Sentry from '@sentry/node';

function configureSentry() {
  Sentry.init({
    dsn: process.env.SENTRY_DSN,
    integrations: [new Sentry.Integrations.Anr({captureStackTrace: true})],
  });
}

async function main() {
  configureSentry();
  await new Promise(resolve => setTimeout(resolve, 1000));
  process.exit(0);
}

main();

Expected Result

The program cleanly exits after 1 second.

Actual Result

The program waits forever with the following console output:

Debugger listening on ws://127.0.0.1:55686/bf184600-b574-49d0-9b00-3640e71b55ed
For help, see: https://nodejs.org/en/docs/inspector
Waiting for the debugger to disconnect...

I can find no workaround.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Jan 2, 2024
  2. timfish commented on Jan 2, 2024

    @timfish
    Collaborator

    Thanks for reporting. Sorry, this was unexpected behaviour and therefore didn't even end up in the test cases.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Jan 2, 2024
  4. joshkel commented on Jan 2, 2024

    @joshkel
    ContributorAuthor

    Thanks, @timfish . I may have been unclear - #10023 and this issue are separate. #10023 is about unrefing the timer, because "natural" exit doesn't work when ANR is enabled. This issue is about explicit process.exit not working when ANR and captureStackTrace are both enabled.

  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Jan 2, 2024
  6. timfish commented on Jan 2, 2024

    @timfish
    Collaborator

    This issue is about explicit process.exit not working when ANR and captureStackTrace are both enabled.

    Ah, thanks for the heads up. I'll test this tomorrow!

  7. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Jan 2, 2024
  8. timfish commented on Jan 2, 2024

    @timfish
    Collaborator

    I couldn't wait but I'll check again tomorrow because it's late...

    With the following code and the timer fix, node exits cleanly after a second:

    const Sentry = require('@sentry/node');
    
    function configureSentry() {
      Sentry.init({
        dsn: 'https://public@dsn.ingest.sentry.io/1337',
        integrations: [new Sentry.Integrations.Anr({ captureStackTrace: false })],
      });
    }
    
    async function main() {
      configureSentry();
      await new Promise(resolve => setTimeout(resolve, 1000));
      process.exit(0);
    }
    
    main();
  9. joshkel commented on Jan 2, 2024

    @joshkel
    ContributorAuthor

    @timfish I apologize; there was a bug in my test case. (That's what I get for trying to do too many things at once...)

    I'm seeing the issue with captureStackTrace: true. I've updated my steps to reproduce.

  10. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Jan 2, 2024
  11. timfish commented on Jan 2, 2024

    @timfish
    Collaborator

    Oh, you're right, it doesn't actually fix it with the timer undef'd. The debugger must keep it alive 😬

  12. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Jan 2, 2024
  13. AbhiPrasad commented on Jan 4, 2024

    @AbhiPrasad
    Contributor

    All the ANR fixes were released with https://github.com/getsentry/sentry-javascript/releases/tag/7.92.0 - please give it a try!

    Thanks for your help + contributions, appreciate it!

  14. ghost added on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions