Skip to content

nextjs (12) withSentry API route wrapper crashes Nodejs with ERR_INTERNAL_ASSERTION #4164

Closed
@killercup

Description

@killercup

Package + Version

  • @sentry/browser 6.15.0
  • @sentry/node 6.15.0
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/nextjs 6.15.0

Version:

6.15.0

Description

I tried adding sentry support to an internal nextjs 12 project. I know version 12 is not supported, so I didn't expect everything to work out of the box.

I am exposing a Apollo Server instance as an API route, using apollo-server-micro like this:

import { ApolloServer } from "apollo-server-micro";
export const apolloServer = new ApolloServer();
const server = apolloServer.start().then(() =>
  apolloServer.createHandler({
    path: "/api/graphql",
  }),
);

async function apolloRequestHandler(req: IncomingMessage, res: ServerResponse) {
  const handler = await server;
  await handler(req, res);
}

To collect errors with sentry I expose this API route like this:

import { withSentry } from "@sentry/nextjs";

export default withSentry(apolloRequestHandler);

In development mode, everything works okay.

yarn && yarn build && yarn start starts the server just fine in production mode, but after one API request the Node process crashes with:

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (internal/errors.js:322:7)
    at assert (internal/assert.js:14:11)
    at ServerResponse.detachSocket (_http_server.js:234:3)
    at resOnFinish (_http_server.js:795:7)
    at ServerResponse.emit (events.js:400:28)
    at ServerResponse.emit (domain.js:537:15)
    at onFinish (_http_outgoing.js:792:10)
    at afterWrite (internal/streams/writable.js:466:5)
    at afterWriteTick (internal/streams/writable.js:453:10)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

As this is not a critical project and I don't have time to dig into this further, I will only use sentry client side for now.

Let me know if you need more information.

Additional info

  • I'm running on the latest node 14 and tested on both PopOS 21.04 as well as in docker using the node:14 image.
  • I'm using prisma for database access, which uses native plugins afaik

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions