-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
fs: deprecate file handle close
#49291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant on fs write stream. Also probably doc deprecate.
You meant:
instead? |
Why (doc or runtime) deprecate |
I don't get it either. A comment in the linked issue says this:
If the suggestion is to let the GC drive closing files, then that's a bad suggestion for what I hope are obvious reasons. |
Why do we need to have three APIs to close a file stream
Absolutely not. The idea from the linked issue is to enable a case where a user wants to open a steam for a FileHandle and keep the file open when the stream is closed (by explicitly opting into it!). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should just be a doc-deprecation of https://nodejs.org/api/fs.html#writestreamclosecallback ?
Why only doc deprecate instead of moving node itself out of using it? |
Throwing will cause unwarranted breakage in the ecosystem. |
I did not mean to throw an error, I think that if deprecating an api we should move away from it as well |
when the user pass In other words, should the following test pass? it('should keep file handle open after stream closed when autoClose: false', async () => {
const filePathForHandle = path.resolve(tmpDir, 'tmp-write.txt');
const stream0Text = 'Hello world from stream0';
const destFile = await open(filePathForHandle, 'w');
await destFile.truncate(stream0Text.length + 20);
const stream0 = destFile.createWriteStream({ start: 0, autoClose: false });
await pipeline(stream0Text, stream0);
stream0.destroy(new Error('destroyed'));
assert.notEqual(destFile.fd, -1);
await destFile.close()
}); |
That's entirely unrelated to this PR and s just context around the linked issue |
What do you think of the PR so far? Is it in the right direction? |
I don't see an actual docs deprecation fo file handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the title of this should be updated, as we are deprecating only close()
for file streams, not file handles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unref isn't right. Will leave a more constructive comment next week.
|
||
// Greater than 2 as when file handle is being created the refs is 1 | ||
// and when the stream is using that file handle the refs is 2 | ||
if (stream[kHandle]?.[kRefs] > 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong.
Created after @ronag comment:
#49241 (comment)
same suggestion from @mcollina to remove the
.close