You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to read from a FIFO file using Node.js but I get 2 different behaviors on macOS and Linux.
On macOS, everything seems working as expected.
On Linux, when a chunk of data is received the FIFO stream is automatically closed.
Here is the code example:
constfs=require('fs');constnet=require('net');constchild_process=require('child_process');constfilename='test';// Clean and create FIFOfs.rmSync(filename,{force: true});child_process.execSync(`mkfifo -m 622 ${filename}`);// Open FIFO// See https://github.com/nodejs/node/issues/23220#issuecomment-426345872constfd=fs.openSync(filename,fs.constants.O_RDONLY|fs.constants.O_NONBLOCK);constfifoStream=newnet.Socket({ fd });// Handle FIFO eventsfifoStream.on('data',data=>console.log('Data received in FIFO stream:',data.toString()));fifoStream.on('close',()=>console.log('FIFO stream closed'));// Send data to FIFOsetInterval(()=>{console.log('Writing data "Test" to FIFO');fs.writeFileSync(filename,'Test');},1000);
On macOS (M1, Node.js v16.13.2, v16.17.1 and v18.12.0), the FIFO stream stays opened and continues to show data received:
$ node test.jsWriting data "Test" to FIFOData received in FIFO stream: TestWriting data "Test" to FIFOData received in FIFO stream: TestWriting data "Test" to FIFOData received in FIFO stream: TestWriting data "Test" to FIFOData received in FIFO stream: TestWriting data "Test" to FIFOData received in FIFO stream: TestWriting data "Test" to FIFOData received in FIFO stream: Test
On Linux (Ubuntu 22.10 with Node.js v18.7.0 and Alpine Linux 3.16.2 with Node.js v16.17.1), the stream close on first chunk of data received:
# node test.jsWriting data "Test" to FIFOData received in FIFO stream: TestFIFO stream closed
How often does it reproduce? Is there a required condition?
Each time on Linux
What is the expected behavior?
Shouldn't close the FIFO stream when a chunk is received
What do you see instead?
Closes the FIFO stream
Additional information
No response
The text was updated successfully, but these errors were encountered:
See #23220 (comment) from the same issue you linked to. The behavior of a FIFO in non-blocking mode is not well-defined, it doesn't even have to behave the same on different versions of the same operating system.
Version
16 & 18 at least
Platform
Linux and macOS
Subsystem
No response
What steps will reproduce the bug?
Hi,
I'm trying to read from a FIFO file using Node.js but I get 2 different behaviors on macOS and Linux.
On macOS, everything seems working as expected.
On Linux, when a chunk of data is received the FIFO stream is automatically closed.
Here is the code example:
On macOS (M1, Node.js v16.13.2, v16.17.1 and v18.12.0), the FIFO stream stays opened and continues to show data received:
On Linux (Ubuntu 22.10 with Node.js v18.7.0 and Alpine Linux 3.16.2 with Node.js v16.17.1), the stream close on first chunk of data received:
How often does it reproduce? Is there a required condition?
Each time on Linux
What is the expected behavior?
Shouldn't close the FIFO stream when a chunk is received
What do you see instead?
Closes the FIFO stream
Additional information
No response
The text was updated successfully, but these errors were encountered: