Skip to content

Out-of-memory error with nextJS at run time #16759

Open
@calvinleeto

Description

@calvinleeto

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

9.33.0

Framework Version

Next: 14.2.25

Link to Sentry event

No response

Reproduction Example/SDK Setup

// instrumentation-client.ts
Sentry.init({
  dsn: process.env.NEXT_PUBLIC_DSN
  sendDefaultPii: false,
  beforeSend(event) {
    event.tags = {
      ...event.tags,
    };
    return event;
  },
  tracesSampler: ({ name, inheritOrSampleWith, attributes }) => {
    return inheritOrSampleWith(someOperations(name, attributes) ?? 0)
  },
  integrations: [Sentry.browserTracingIntegration()],
});

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
// instrumentation.ts
export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await import("./sentry.server.config");
  }
}
// sentry.server.config.ts
Sentry.init({
  dsn: env("NEXT_PUBLIC_DSN"),
  sendDefaultPii: false,
  beforeSend(event) {
    event.tags = {
      ...event.tags,
    };
    return event;
  },
  tracesSampler: ({ name, inheritOrSampleWith }) => {
    return inheritOrSampleWith(0);
  },
});

Steps to Reproduce

  1. npm run build works perfectly with enabling sourcemap and uploading it to Sentry
  2. When running the app on production (npm run start), I observe that there is a gradual uptrend for the memory usage of a pod.
  3. Eventually, it reached the memory limit of a pod, causing the pod to be killed.
  4. node -v // v22.17.0

Expected Result

Memory usage should not gradually increase over time

Actual Result

Fatal Error: Reached heap limit allocation failed javascript heap out of memory
Memory leak should not happen

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions