Skip to content

Commit 4652f2c

Browse files
committed
Fix MlNodeFd initialization
We are using fstat to test whether the file is seekable. This function fails on standard streams under Windows with node 18 (and lower). See libuv/libuv#3811. So, we just assume that the file is not seekable in case an exception is risen.
1 parent 51c1335 commit 4652f2c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
## Bug fixes
1212
* Runtime: fix path normalization (#1848)
13+
* Runtime: fix initialization of standard streams under Windows (#1849)
1314

1415
# 6.0.1 (2025-02-07) - Lille
1516

runtime/js/fs_node.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,15 @@ class MlNodeFd extends MlFile {
392392
this.fs = require("node:fs");
393393
this.fd = fd;
394394
this.flags = flags;
395-
var stats = this.fs.fstatSync(fd);
396-
flags.noSeek =
397-
stats.isCharacterDevice() || stats.isFIFO() || stats.isSocket();
395+
try {
396+
var stats = this.fs.fstatSync(fd);
397+
flags.noSeek =
398+
stats.isCharacterDevice() || stats.isFIFO() || stats.isSocket();
399+
} catch (err) {
400+
// The fstat will fail on standard streams under Windows with node
401+
// 18 (and lower). See https://github.com/libuv/libuv/pull/3811.
402+
flags.noSeek = true;
403+
}
398404
this.offset = this.flags.append ? stats.size : 0;
399405
this.seeked = false;
400406
}

0 commit comments

Comments
 (0)