Skip to content

Memory leak in Sentry.withScope #18220

@joulev

Description

@joulev

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

10.25.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from "@sentry/node";
import v8 from "node:v8";

Sentry.init({ dsn: "<DSN HERE>" });

let count = 0;

function handle() {
  gc?.();

  const largeData = new Array(1000000).fill("hello");
  Sentry.withScope((scope) => {
    scope.setExtra("data", largeData);
    Sentry.captureMessage("hello");
  });

  const heapData = v8.getHeapStatistics();
  count++;
  if (count % 20 === 0) {
    console.log(`${heapData.total_heap_size}`);
  }
}

console.log(Sentry.SDK_VERSION);
while (true) {
  handle();
}

Steps to Reproduce

Run the above script with node --expose-gc.

$ node --expose-gc script.mjs

Expected Result

The logged value can fluctuate but should not go up.

Actual Result

10.25.0
213172224
373407744
533643264
693878784
854114304
1014349824
1174585344
1334820864
1495056384
1655291904
1815527424
1975762944
2136260608
2296496128
2456993792
2617491456
2777726976
2938224640
3098460160
3258957824
3419193344

<--- Last few GCs --->

[39532:0xb83400000]    66593 ms: Mark-Compact 3298.9 (3337.5) -> 3298.9 (3337.5) MB, pooled: 0 MB, 289.38 / 0.00 ms  (average mu = 0.006, current mu = 0.007) testing; GC in old space requested
[39532:0xb83400000]    67044 ms: Mark-Compact 3306.6 (3345.1) -> 3306.5 (3345.1) MB, pooled: 0 MB, 448.04 / 0.00 ms  (average mu = 0.006, current mu = 0.005) testing; GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
(and a bunch of other things)

Additional Context

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions