sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Unhandled Promise Rejection in debugger on Node startup

Open mwenko opened this issue 1 year ago • 11 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.7.0

Framework Version

8.7.0

Link to Sentry event

No response

SDK Setup

Sentry.init({
            dsn: dsn,
            environment: environmentWithAppInstance,
            debug: true,
            maxValueLength: maxValueLength,
            release: version,
            integrations: [nodeProfilingIntegration()],
            skipOpenTelemetrySetup: true,
            tracesSampler: (context) => {
                if (context.request?.url?.endsWith("/status")) {
                    return 0;
                }

                return defaultTraceSampleRate;
            },
            profilesSampleRate: profilesSampleRate,
            beforeBreadcrumb(breadcrumb, _) {
                if (!shouldAddBreadcrumb(breadcrumb)) {
                    return null;
                }

                return breadcrumb;
            },

            beforeSend(event: ErrorEvent, hint: Sentry.EventHint) {
                if (!shouldSend(hint)) {
                    return null;
                }

                event = removeAuthorizationHeader(event);

                return event;
            },
        });

Steps to Reproduce

  1. Run nest start --debug --watch

Node: 20.9.0 NestJS: 10.3.8

Expected Result

The application should start without throwing an unhandled promise rejection.

Actual Result

It throws an unhandled promise rejection (see screenshot):

image

If I unmark "uncaught exception" in my editor it starts like expected.

mwenko avatar Jun 04 '24 08:06 mwenko

This error isn't unhandled as it has a .catch(). You're likely hitting this in the debugger because you have Pause on caught exceptions enabled:

image

timfish avatar Jun 04 '24 09:06 timfish

This error isn't unhandled as it has a .catch(). You're likely hitting this in the debugger because you have Pause on caught exceptions enabled:

image

Thanks for the quick response.

If you look at the provided screenshot, you'll see that I have Uncaught Exception marked in the breakpoints section. (bottom left corner)

(I noticed that the code has a catch() applied. And it made the issue even weirder to me)

mwenko avatar Jun 04 '24 11:06 mwenko

I think you're seeing this: https://github.com/microsoft/vscode/issues/116783

Which has a linked v8 dev tools issue which is still open: https://issues.chromium.org/issues/41161875

The argument is that debugger should not break here because the exception is later caught.

Without the debugger attached, this does not result in an unhandled promise rejection.

timfish avatar Jun 04 '24 11:06 timfish

I've opened a PR in opentelemetry-instrumentation-fetch-node which should stop this from hitting the debugger issue.

timfish avatar Jun 04 '24 11:06 timfish

Hmm, I still experiencing this issue (using the latest release 8.17.0). The debugger stops because of an "unhandled promise rejection".

image

mwenko avatar Jul 10 '24 13:07 mwenko

I don't understand how this could be uncaught when there is a catch block right below it 🤔

Maybe this is because of how fetch internals work?

AbhiPrasad avatar Jul 10 '24 14:07 AbhiPrasad

I've opened a PR in opentelemetry-instrumentation-fetch-node which should stop this from hitting the debugger issue.

@timfish Did you test this PR if it resolves the issue?

mwenko avatar Jul 12 '24 12:07 mwenko

@timfish Did you test this PR if it resolves the issue?

No sorry. I looked at the open Chromium debugger issues and the causes and then made assumptions based on that and what I know about how awaiting promises vs then work.

As @AbhiPrasad says above, the changes I made should have fixed this but the fact that it hasn't suggests this rejection is triggered by the fetch internals.

timfish avatar Jul 12 '24 12:07 timfish

@timfish

I opened a PR where the issue has been resolved in my project (running against 8.19 of Sentry)

https://github.com/gas-buddy/opentelemetry-instrumentation-fetch-node/pull/16

mwenko avatar Jul 22 '24 15:07 mwenko

We're going to drop opentelemetry-instrumentation-fetch-node in favour of @opentelemetry/instrumentation-undici which should help solve this issue. I'll respond in this issue when this makes it into a release.

timfish avatar Aug 14 '24 10:08 timfish

We're going to drop opentelemetry-instrumentation-fetch-node in favour of @opentelemetry/instrumentation-undici which should help solve this issue. I'll respond in this issue when this makes it into a release.

Thank you for the update. I think it's a good decision to go with the official package.

mwenko avatar Aug 19 '24 14:08 mwenko

We've released https://github.com/getsentry/sentry-javascript/releases/tag/8.30.0 with using the official package.

AbhiPrasad avatar Sep 10 '24 14:09 AbhiPrasad

We've released https://github.com/getsentry/sentry-javascript/releases/tag/8.30.0 with using the official package.

Great work - it works!

mwenko avatar Sep 11 '24 03:09 mwenko