Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fs: don't block stream destroy if there are other handle refs
  • Loading branch information
ronag committed Dec 19, 2022
commit 5cca6cbf34fa2a129535d4e9cfbebfe993353c25
9 changes: 7 additions & 2 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ const FileHandleOperations = (handle, closeHandler) => {
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.


handle[kUnref]();
PromisePrototypeThen(handle.close(),
() => 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

} else {
PromisePrototypeThen(handle.close(),
() => cb(), cb);
}
},
read: (fd, buf, offset, length, pos, cb) => {
PromisePrototypeThen(handle.read(buf, offset, length, pos),
Expand Down