nodejs / nodejs/node

fs.realpath infinite loop

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

还没有人认领这个 Issue。

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

描述

Version

v25.0.0

Platform
uname -a
Linux [hostname] 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Subsystem

fs

What steps will reproduce the bug?
$ mkdir test
$ cd test
$ mkdir -p a/b/{c,d}
$ ln -s a/b/c  # Make symlink to c dir in a/b
$ ln -s "c/../d"  # Make symlink to d dir via c symlink
$ node -e "const fs = require('fs'); console.log(fs.realpathSync('d'));"

The node call never returns. If I call it with strace it's just checking the same file over and over:

...
statx(AT_FDCWD, "/home/niko/test/d", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFLNK|0777, stx_size=6, ...}) = 0
statx(AT_FDCWD, "/home/niko/test/d", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFLNK|0777, stx_size=6, ...}) = 0
...
How often does it reproduce? Is there a required condition?

Reproduces every time.

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

Expected behavior is that the realpath would be printed to the console:

$ node -e "const fs = require('fs'); console.log(fs.realpathSync('d'));"
/home/niko/test/a/b/d

Note that realpathSync.native does work properly:

$ node -e "const fs = require('fs'); console.log(fs.realpathSync.native('d'));"
/home/niko/test/a/b/d
What do you see instead?

An infinite loop (see Steps section above).

Additional information

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先在 Linux 上复现 fs.realpathSync('d'),并将其与 fs.realpathSync.native('d') 进行比较,以报告中的 symlink 设置和 strace 行为作为指导。跟踪 fs.realpathSync 入口点及其 symlink 解析路径。当命令返回 /home/niko/test/a/b/d 而不是陷入循环,同时 native 行为仍然正确时,即表示完成。

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

评估

技术栈
javascript
领域
operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

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