Running a process with DevTools debugger attached leaks memory
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
- Version: 14.0+ (reproduced on
v14.0.0,v14.17.0andv16.1.0) - Platform: Linux
- Tested process: https://github.com/Supinic/supibot
- Valgrind tests by: https://github.com/Leppunen
While the Chromium DevTools debugger is attached, RSS memory usage of a Node process keeps increasing without being collected. Once the debugger is detached, the memory usage flattens, however the memory is never released. When the debugger is not attached to the process in its runtime, memory allocation occurs as expected. It is entirely possible that this might not be related to Node (v8, perhaps) - however, this issue might be a good place to start a discussion.
Inspecting htop on a Raspberry Pi 3B machine:
-
Process after running for ~24 hours without a debugger attached: stable at around ~180MB RSS:

-
The same process, after attaching the debugger for ~15 minutes (with no actual user debugging active nor any logs being displayed): RSS at around ~245MB and rising:

-
After disconnecting the debugger (removing the connection, closing and re-opening the debugger window), RSS stabilizes at around ~260MB. After ~30 minutes of further activity, the RSS usage seems stable; however, the memory is not freed:

After running valgrind for various amounts of time on a different Linux machine, there seems to be an excessive amount of v8_inspector::AsyncStackTrace::capture calls. Using the Disable async stack traces option in DevTools > Settings > Debugger seems to reduce the leak somewhat, however, this wasn't reproducible across machines. Furthermore, testing the same process on Windows 10 in the same environment leads to no memory leaks.
Attached are valgrind dumps for various tested nodejs versions. Note that each dump was created with the process running for differing amounts, hence the total memory leaked will not be as relevant.
What steps will reproduce the bug?
- Set up a Node process, possibly with asynchronous stack activity
- Attach a Chrome DevTools debugger instance
- Observe a memory leak as long as the debugger is attached
How often does it reproduce? Is there a required condition?
- Only seems to reproduce on Linux, not Windows
- Might be related to async stack traces
- At first, seemed to be related to the
mariadbNPM module - but upon further testing with the module inactive, the memory leak kept occuring
What is the expected behavior?
No memory leak should occur as the debugger is being used.
What do you see instead?
Depending on the process being run, upwards of hundreds of MB of RAM will leak in a couple of minutes as the debugger is attached.
Additional information
A similar type of memory leak seems to be present in versions prior to 14.0, however, in a much smaller scale, and occuring much more slowly. Reference: nodejs/node#28787, possibly nodejs/node#28420
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先按照列出的步骤在 Linux 上复现 leak,并连接 Chrome DevTools,然后比较启用和禁用 async stack traces 时的运行结果。检查提供的 Valgrind 转储以及 v8_inspector::AsyncStackTrace::capture 的过度活动;完成标准是使用调试器不再导致 RSS 持续增长或内存未释放。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, nodejs
- 领域
- performance, tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100