AbortSignal.any() causes memory leak

未关闭
#54,614 12 条评论 6 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
javascript
领域
backend

调研方向

从 issue 中描述的 AbortSignal.any() 入口点开始,并在 Node.js 上运行提供的 JavaScript 复现代码,以确认内存增长。跟踪组合 signal 如何保留其输入 signal,并确定何时应释放这些引用。完成的标准是,重复创建单 signal 组合不再导致持续的内存增长,并使用复现代码验证该行为。

由索引模型根据 Issue 内容生成。

描述

abortcontroller memory
Version

v22.6.0

Platform
Microsoft Windows NT 10.0.22631.0 x64
Linux ****** 4.4.0-22621-Microsoft #3672-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 x86_64 x86_64 GNU/Linux
Subsystem

https://nodejs.org/api/globals.html#class-abortsignal

What steps will reproduce the bug?

Run this and watch memory usage.

const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;

let memoryData = process.memoryUsage();
console.log('Mem before loop', formatMemoryUsage(memoryData.rss));

for (let i = 0; true; i++) {
    const abortController = new AbortController();
    const signal = abortController.signal;
    const composedSignal = AbortSignal.any([signal]);

    if (i === 1000000) {
        break;
    }
}

memoryData = process.memoryUsage();
console.log('Mem after 1 million iteration', formatMemoryUsage(memoryData.rss));

This is what I get on my local machine
image

How often does it reproduce? Is there a required condition?

Always reproducible as far as I can tell

What is the expected behavior? Why is that the expected behavior?

Memory post loop execution should be fairly equivalent to the first log but somehow the const composedSignal = AbortSignal.any([signal]); does not get cleaned up from memory, I would expect this to get cleaned properly or if this is the intended behavior to have a clear warning in the documentation.

What do you see instead?

We see a memory leak that will eventually lead to an out of memory error.

Additional information

This has been tested on Node 22.6 on different machine and both Windows + Unix versions. Happy to provide more details if needed

主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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