nodejs / nodejs/node

fs.realpath infinite loop

Offen
#60,295 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Reproduktion von fs.realpathSync('d') unter Linux und vergleiche sie mit fs.realpathSync.native('d'), wobei die gemeldete Symlink-Konfiguration und das Verhalten von strace als Orientierung dienen. Verfolge den Einstiegspunkt fs.realpathSync und den Pfad zur Auflösung des Symlinks. Erledigt ist die Aufgabe, wenn der Befehl /home/niko/test/a/b/d zurückgibt, anstatt in einer Schleife zu laufen, während das native Verhalten weiterhin korrekt bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.