getsentry / getsentry/sentry-javascript

Memory leak in Sentry.withScope

未关闭
#18,220 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
Bug Node.js
主要语言
TypeScript
星标
8.7k
派生
1.8k
平均合并
1 天 17 小时
30 天内合并 PR
515

描述

### Is there an existing issue for this?

- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [x] I have reviewed the documentation https://docs.sentry.io/
- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

### 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

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

Sentry.init({ dsn: "" });

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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。