fs: remove FileHandle stream close listener#64229
Open
ishaanlabs-gg wants to merge 2 commits into
Open
Conversation
mcollina
reviewed
Jul 1, 2026
| options.fd.on('close', FunctionPrototypeBind(stream.close, stream)); | ||
| stream[kHandleCloseListener] = FunctionPrototypeBind(stream.close, stream); | ||
| stream[kHandleCloseListenerCleanup] = FunctionPrototypeBind( | ||
| cleanupHandleCloseListener, stream); |
Member
There was a problem hiding this comment.
This is not needed if not autoclosing. move it inside the if.
f937b9a to
98b30c4
Compare
98b30c4 to
59c7463
Compare
Author
|
Addressed the review feedback by only installing the FileHandle close listener for |
davidje13
reviewed
Jul 1, 2026
Comment on lines
+162
to
+165
| 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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