Repository navigation
fs: handle fixes - #45909
Closed
ronag wants to merge 5 commits into
Closed
fs: handle fixes#45909ronag wants to merge 5 commits into
ronag wants to merge 5 commits into
Conversation
ronag
referenced
this pull request
Dec 19, 2022
Support creating a Read/WriteStream from a FileHandle instead of a raw file descriptor Add an EventEmitter to FileHandle with a single 'close' event. Fixes: #35240 PR-URL: #35922 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
ronag
marked this pull request as ready for review
December 25, 2022 11:12
Member
Author
|
@nodejs/fs @mcollina |
ronag
commented
Dec 25, 2022
| throw new ERR_METHOD_NOT_IMPLEMENTED('open()'); | ||
| }, | ||
| close: (fd, cb) => { | ||
| handle.off('close', closeHandler); |
Member
Author
There was a problem hiding this comment.
Avoid keeping stream alive until file handle is closed.
ronag
commented
Dec 25, 2022
| () => cb(), cb); | ||
| if (handle[kFd] !== -1) { | ||
| // Someone else has a ref to the handle. | ||
| process.nextTick(cb); |
Member
Author
There was a problem hiding this comment.
stream can finish teardown even if file handle isn't closed, if it has refs
ronag
commented
Dec 25, 2022
| () => { this[kClosePromise] = undefined; } | ||
| () => { | ||
| this[kClosePromise] = undefined; | ||
| this.emit('close'); |
Member
Author
There was a problem hiding this comment.
Only emit close after actually closing.
Contributor
|
I'm afraid this PR flew under people's radar. |
aduh95
reviewed
Mar 3, 2023
aduh95
left a comment
Contributor
There was a problem hiding this comment.
LGTM except the test failures
aduh95
reviewed
Mar 3, 2023
aduh95
left a comment
Contributor
There was a problem hiding this comment.
LGTM except the test failures
SahinurDEV
added a commit
to SahinurDEV/node
that referenced
this pull request
Oct 12, 2026
When a ReadStream or WriteStream is created from a FileHandle, the stream takes a reference on the handle. Destroying the stream (for example by breaking out of a `for await` loop) dropped that reference and then unconditionally called `filehandle.close()`, which also dropped the caller's reference and closed the handle, even when the stream was created with `autoClose: false`. Only release the stream's own reference when `autoClose` is false, so that the FileHandle stays usable and remains owned by the caller, as documented. Also remove the stream's 'close' listener from the FileHandle when the stream closes, so that creating many streams from a long-lived FileHandle does not leak listeners and streams. Fixes: nodejs#45721 Refs: nodejs#45909 Signed-off-by: Sahinur <[email protected]>
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.
Minor fixes found while reviewing code. I don't plan on working further on this so if someone wants to finish up with the test be my guest.