Skip to content

fs: handle fixes - #45909

Closed
ronag wants to merge 5 commits into
nodejs:mainfrom
nxtedition:fixes-123
Closed

ronag wants to merge 5 commits into
nodejs:mainfrom
nxtedition:fixes-123

Conversation

@ronag

@ronag ronag commented Dec 19, 2022

Copy link
Copy Markdown
Member

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.

@ronag ronag added the good first issue Issues that are suitable for first-time contributors. label Dec 19, 2022
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Dec 19, 2022
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
ronag requested a review from aduh95 December 25, 2022 11:12
@ronag
ronag marked this pull request as ready for review December 25, 2022 11:12
@ronag ronag removed the good first issue Issues that are suitable for first-time contributors. label Dec 25, 2022
@ronag

ronag commented Dec 25, 2022 •

Copy link
Copy Markdown
Member Author

@nodejs/fs @mcollina

throw new ERR_METHOD_NOT_IMPLEMENTED('open()');
},
close: (fd, cb) => {
handle.off('close', closeHandler);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid keeping stream alive until file handle is closed.

() => cb(), cb);
if (handle[kFd] !== -1) {
// Someone else has a ref to the handle.
process.nextTick(cb);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream can finish teardown even if file handle isn't closed, if it has refs

() => { this[kClosePromise] = undefined; }
() => {
this[kClosePromise] = undefined;
this.emit('close');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only emit close after actually closing.

@ronag ronag added the review wanted PRs that need review. label Jan 1, 2023
@Slayer95

Slayer95 commented Mar 3, 2023

Copy link
Copy Markdown
Contributor

I'm afraid this PR flew under people's radar.

@aduh95 aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the test failures

@aduh95 aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the test failures

@ronag ronag closed this Apr 8, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. review wanted PRs that need review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants