Skip to content

Commit 6b64ffc

Browse files
authored
Avoid closing standard streams under NODERAWFS (#24755)
Fixes: #24730
1 parent 31de69d commit 6b64ffc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib/libnoderawfs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ addToLibrary({
173173
},
174174
close(stream) {
175175
VFS.closeStream(stream.fd);
176-
if (!stream.stream_ops && --stream.shared.refcnt <= 0) {
176+
// Don't close stdin/stdout/stderr since they are used by node itself.
177+
if (!stream.stream_ops && --stream.shared.refcnt <= 0 && stream.nfd > 2) {
177178
// This stream is created by our Node.js filesystem, close the
178179
// native file descriptor when its reference count drops to 0.
179180
fs.closeSync(stream.nfd);

test/test_other.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10451,9 +10451,12 @@ def test_toolchain_profiler_stderr(self):
1045110451

1045210452
@also_with_wasmfs
1045310453
@crossplatform
10454-
def test_noderawfs(self):
10455-
self.run_process([EMXX, test_file('fs/test_fopen_write.cpp'), '-sNODERAWFS'] + self.get_cflags())
10456-
self.assertContained("read 11 bytes. Result: Hello data!", self.run_js('a.out.js'))
10454+
@parameterized({
10455+
'': ([],),
10456+
'runtime_debug': (['-sRUNTIME_DEBUG', '-sEXIT_RUNTIME', '-pthread'],),
10457+
})
10458+
def test_noderawfs_basics(self, args):
10459+
self.do_runf('fs/test_fopen_write.cpp', 'read 11 bytes. Result: Hello data!', cflags=['-sNODERAWFS'] + args)
1045710460

1045810461
# NODERAWFS should directly write on OS file system
1045910462
self.assertEqual("Hello data!", read_file('hello_file.txt'))

0 commit comments

Comments
 (0)