-
-
Notifications
You must be signed in to change notification settings - Fork 36.5k
fs: fix close listener leak in FileHandle streams #64227
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -152,7 +152,19 @@ function importFd(stream, options) { | |||||||||||||||||||||||||||||||||||
| stream[kHandle] = options.fd; | ||||||||||||||||||||||||||||||||||||
| stream[kFs] = FileHandleOperations(stream[kHandle]); | ||||||||||||||||||||||||||||||||||||
| stream[kHandle][kRef](); | ||||||||||||||||||||||||||||||||||||
| options.fd.on('close', FunctionPrototypeBind(stream.close, stream)); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const onclose = FunctionPrototypeBind(stream.close, stream); | ||||||||||||||||||||||||||||||||||||
| options.fd.on('close', onclose); | ||||||||||||||||||||||||||||||||||||
| if (options.autoClose === false) { | ||||||||||||||||||||||||||||||||||||
| function cleanup() { | ||||||||||||||||||||||||||||||||||||
| options.fd.removeListener('close', onclose); | ||||||||||||||||||||||||||||||||||||
| options.fd[kUnref](); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| stream.once('end', cleanup); | ||||||||||||||||||||||||||||||||||||
| stream.once('finish', cleanup); | ||||||||||||||||||||||||||||||||||||
| stream.once('error', cleanup); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+159
to
+165
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Y1D7NG should we
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I'm aware of for similar functions, it's common practice to (intentionally) leave these listeners dangling on the stream and rely on normal garbage collection to tidy it all up in the end. There was some discussion on this stuff in #35452. In this case, the duplex stuff doesn't apply so I'd personally say it doesn't need the special handling that was eventually added there.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for bringing that, that's interesting. Unsure how to proceed then. @nodejs/streams is the current behavior as expected?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be clear: in my comment I'm only talking about the events on the stream (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 2 approvals and a green CI. Could this PR be landed, or does it need clarification of the above comments first?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My comments are non-blocking, although I don't see it hurting waiting extra time to get insights from the right team tho.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the listeners can be left to normal garbage collection |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return options.fd.fd; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.