Version
v19.2.0, v14.21.1
Platform
Linux wolf-x1c6 5.15.0-53-generic #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
importfsPromisesfrom'node:fs/promises'constfh=awaitfsPromises.open('example.txt')fh.on('close',()=>{thrownewError('handle closed!')})conststream=fh.createReadStream({autoClose: false,})forawait(constchunkofstream){break}// Give the event loop a breather: this seems to be where the close happensawaitnewPromise(resolve=>setTimeout(resolve,10))console.log('fd',fh.fd)// = -1; stream closedHow often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
FileHandle.createReadStream({autoClose: false}) should result in the file handle not being automatically closed when the stream is destroyed.
What do you see instead?
Using fs.ReadStream[Symbol.asyncIterator] seems to unconditionally close the file handle (after a small delay; I guess at the end of the event loop or something? but haven't dug in; just noted the setTimeout above is necessary to reproduce) despite {autoClose: false} being passed to FileHandle.createReadStream().
This seems to be the result of the underlying readable.destroy() also closing the file handle; but it means that, as far as I can tell, there's no way to only partially consume an fs.ReadStream created from a file handle without either closing the handle or leaking the stream.
Additional information
No response
Version
v19.2.0, v14.21.1
Platform
Linux wolf-x1c6 5.15.0-53-generic #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
FileHandle.createReadStream({autoClose: false})should result in the file handle not being automatically closed when the stream is destroyed.What do you see instead?
Using
fs.ReadStream[Symbol.asyncIterator]seems to unconditionally close the file handle (after a small delay; I guess at the end of the event loop or something? but haven't dug in; just noted thesetTimeoutabove is necessary to reproduce) despite{autoClose: false}being passed toFileHandle.createReadStream().This seems to be the result of the underlying
readable.destroy()also closing the file handle; but it means that, as far as I can tell, there's no way to only partially consume anfs.ReadStreamcreated from a file handle without either closing the handle or leaking the stream.Additional information
No response