sentry-javascript: Node.js 12 "Cannot read property 'enter' of undefined"

Package + Version

  • @sentry/node
  • @sentry/integrations

Version:

@sentry/node 5.3.0
@sentry/integrations 5.3.1
Node.js 12.3.1

Description

After switching to Node 12.3.1 I started to have hard crashes of my application this way:

TypeError: Cannot read property 'enter' of undefined
    at AsyncHook.before (domain.js:76:20)
    at emitHook (internal/async_hooks.js:164:38)

Here’s how we use Sentry (relevant lines only):

const express = require('express');
const app = express();
const Sentry = require('@sentry/node');
const SentryIntegrations = require('@sentry/integrations');
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  environment: process.env.APP_ENV,
  release: `support@${process.env.HEROKU_RELEASE_VERSION}`,
  integrations: [
    new SentryIntegrations.ExtraErrorData(),
    new SentryIntegrations.Transaction(),
  ],
});
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.errorHandler());
module.exports = app;

After checking our code I believe the only places where Node.js domains are used are Sentry code. This is why I am opening this issue.

Recent changes to async_handlers linked to domains: https://github.com/nodejs/node/commit/04355eff5bc604cb639f91d159ce21971e2c3bb4#commitcomment-33702918

Let me know if you need anything else.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 43 (7 by maintainers)

Most upvoted comments

fyi @vvo @BYK @kamilogorek @emhagman @kunal15595 - I came across your issue here as I had the exact same error show up in my hapi servers (no sentry) with node > 12.2.

I believe it was caused by https://github.com/nodejs/node/issues/28275. The fix for that issue was merged 5 days ago with https://github.com/nodejs/node/commit/43e5478e2f51343b66f4d243bb4800d8e422f764 and hopefully will be released soon and resolve our issue.

When an uncaught exception is thrown inside a domain, the domain is removed from the stack as of 43a5170. This means that it might not be kept alive as an object anymore, and may be garbage collected before the after() hook can run, which tries to exit it as well.

Resolve that by making references to the domain strong while it is active.

@emhagman Yep same for me, 12.10 is triggering it too.

Just experienced this same issue in 12.10 which came out on September 3rd. Not sure this is fixed.

For everyone here, the fix has landed in here https://github.com/nodejs/node/commit/d26a74dca0d04a827140a33a43c38a55f12c7296

It should be released into 13.x soon and then two weeks later into 12.x so keep any eye out

I’ve posted a bug report on the NodeJS repo. Hopefully, someone has some insight as to why it might be happening https://github.com/nodejs/node/issues/30122

I’ve also encountered this issue upon upgrading to NodeJS 12.6.0

Getting this on node v12.6.0, sentry v5.5.0 fixed by reverting to v12.2.0