Skip to content

async hook stack has become corrupted #3585

Closed
@Tchoupinax

Description

@Tchoupinax

Hello,

I met strange error after I added sentry to my project. When the error is thrown, the project crashes immediatly.

this:

 Error: async hook stack has become corrupted (actual: 286, expected: 0)

or this:

 Error: async hook stack has become corrupted (actual: 908, expected: 0)

sometimes this:

 node[1]: ../src/api/callback.cc:125:void node::InternalCallbackScope::Close(): Assertion `(env_->execution_async_id()) == (0)' failed.

I know it comes with sentry because I tried to remove Sentry.init and the error disappears.
In my project, I'm using the async_hooks API and I fear a conflict with your tracing SDK. I am using async_hooks this way:

const { AsyncLocalStorage } = require('async_hooks');
const store = new AsyncLocalStorage();

// ...

app.use((req, res, next) => {
  store.enterWith(new Map());

  const instance = store.getStore();
  instance.set('request-id', uuid());

  return next();
});

I am declaring Sentry this way

Sentry.init({
    environment: process.env.NODE_ENV,
    dsn: '__',
    integrations: [
      // enable HTTP calls tracing
      new Sentry.Integrations.Http({ tracing: true }),
      // enable Express.js middleware tracing
      new Tracing.Integrations.Express({ app: router }),
    ],

    // Set tracesSampleRate to 1.0 to capture 100%
    // of transactions for performance monitoring.
    // We recommend adjusting this value in production
    tracesSampleRate: 1.0,
  });

  // RequestHandler creates a separate execution context using domains, so that every
  // transaction/span/breadcrumb is attached to its own Hub instance
  router.use(Sentry.Handlers.requestHandler());
  // TracingHandler creates a trace for every incoming request
  router.use(Sentry.Handlers.tracingHandler());

Do you know how this issue could be solved ?

Thank you for your work :)

Version

Node: 16 (Using Docker image node:16-alpine)

Packages

@sentry/node: 6.4.1
@sentry/tracing: 6.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions