[bug]: Memory leak in Node requester
还没有人认领这个 Issue。
- #1612 来自 @Steve0x2a —— 已关闭,未合并
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- node.js, typescript
调研方向
从 packages/requester-node-http/src/createHttpRequester.ts 开始,尤其关注报告中链接的 end handler,并在 Node's inspector 下使用提供的 index.mjs 脚本重现泄漏。跟踪哪些 request 和 response listener 保留了 error handler,然后验证重复搜索不再使所有 response 保持存活,并且 heap 使用量可以在 garbage collection 后趋于稳定。
由索引模型根据 Issue 内容生成。
描述
Description
We got reports of memory leaks from users of React InstantSearch with Next.js.
It's easy to reproduce, with an index.mjs file :
import process from 'process';
import { algoliasearch } from 'algoliasearch';
process.stdin.resume();
const client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
for (let i = 0; i < 1000; i++) {
client.search({ requests: [{ indexName: 'instant_search' }] });
}
Then run node --inspect index.mjs, in Chrome open chrome://inspect and select index.mjs.
In the memory tab, the VM instance heap size hovers around 90MB without ever going down.
All responses are retained by the error handler.
I tried patching it by adding req.removeAllListeners() as well as response.removeAllListeners() in this end handler : https://github.com/algolia/algoliasearch-client-javascript/blob/36ccbc9799823ccb4868460292f921d1929941e6/packages/requester-node-http/src/createHttpRequester.ts#L60-L69
It's not perfect but it now settles around 20MB. Some unnecessary values are still there but maybe this will properly get GC'd if needed.
I told them to use requester-fetch instead as it's now supported by recent versions of Node.js. Maybe we could make that the default ? From my own benchmarks it seems better than the Node requester currently but with my proposed fix it would make the Node requester more performant than the fetch one 😅 (with undici)
Client
All
Version
5.15.0
Relevant log output
No response
- 主要语言
- TypeScript
- 星标
- 1.4k
- 派生
- 227
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
algolia/algoliasearch-client-javascript 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
algolia/algoliasearch-client-javascript#1583 · 14 条评论 · 9 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 38/100
-
[bug]: Algolia JS Client cause `Bun` to crash on `Hono`可能重新可做 @PrevailUgah 于 238 天前认领,目前没有进行中的 PR。 未关闭bug
难度 4/5 3-5 天 新手友好度 35/100
algolia/algoliasearch-client-javascript#1601 · 5 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
-
bug
难度 3/5 1-2 天 新手友好度 45/100
algolia/algoliasearch-client-javascript#1594 · 4 条评论 ·
查看 algolia/algoliasearch-client-javascript 的全部 Issue
相似的 Issue
-
Diagram: Gantt qa-manually-tested Type: Bug / Error
难度 2/5 1-3 小时 新手友好度 65/100
mermaid-js/mermaid-v13#1255 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 82/100
BaseAdresseNationale/adresse.data.gouv.fr#2620 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复