fs: remove FileHandle stream close listener#64229
Conversation
| options.fd.on('close', FunctionPrototypeBind(stream.close, stream)); | ||
| stream[kHandleCloseListener] = FunctionPrototypeBind(stream.close, stream); | ||
| stream[kHandleCloseListenerCleanup] = FunctionPrototypeBind( | ||
| cleanupHandleCloseListener, stream); |
There was a problem hiding this comment.
This is not needed if not autoclosing. move it inside the if.
98b30c4 to
59c7463
Compare
|
Addressed the review feedback by only installing the FileHandle close listener for |
| stream.once('close', stream[kHandleCloseListenerCleanup]); | ||
| stream.once('end', stream[kHandleCloseListenerCleanup]); | ||
| stream.once('finish', stream[kHandleCloseListenerCleanup]); | ||
| stream.once('error', stream[kHandleCloseListenerCleanup]); |
There was a problem hiding this comment.
I'm pretty sure you don't need to listen for close here, since there will always be either an end (reader) or finish (writer), or an error. Listening for close just doubles-up the call (which is fine because the function protects against being called multiple times, but unnecessary)
968e2ad to
610d021
Compare
|
Updated this to address the follow-up review: the stream no longer registers a FileHandle Validation: Result: focused test passed. |
Fixes: #64214
This removes the extra
FileHandleclose listener that can be left behind bystreams created with
autoClose: false.The listener still lets the stream close if the
FileHandleis closed first,but
autoClose: falsestreams now remove that listener and release the extrastream reference when the stream finishes or closes on its own.
The change also keeps the default
autoClosebehavior covered so read andwrite streams still close their
FileHandleas before.Tests:
./out/Release/node --check lib/internal/fs/streams.js./out/Release/node test/parallel/test-fs-promises-file-handle-stream.jspython3 tools/test.py -J --mode=release parallel/test-fs-promises-file-handle-stream