-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
child_process: check for closed pipes after creating socket #38716
base: main
Are you sure you want to change the base?
child_process: check for closed pipes after creating socket #38716
Conversation
After the socket is created, we trigger an empty read to make sure we catch stdio events like closing the stdin file descriptor. Otherwise those events will go undetected until the next stream write. Fixes: nodejs#25131
Hey @seangoedecke, sorry your PR was not reviewed for so long! Any chance you would be able to rebase on top of |
@@ -447,6 +447,10 @@ ChildProcess.prototype.spawn = function(options) { | |||
stream.socket = createSocket(this.pid !== 0 ? | |||
stream.handle : null, i > 0); | |||
|
|||
// Trigger an empty read to check for a closed pipe | |||
// or the close event will go undetected until next write |
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.
// or the close event will go undetected until next write | |
// or the close event will go undetected until next write. |
const fs = require('fs'); | ||
|
||
if (process.argv[2] === 'child') { | ||
fs.closeSync(0); |
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.
Any reason to use closeSync(0)
rather than process.stdin.end()
? If so, can you add a comment?
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.
as far as I understand the closeSync(0)
is used because it needs to immediately close the standard input stream synchronously, however it's really good question why we cannot asynchronous handling of the end of the input stream?
After the socket is created, this PR now triggers an empty read to make sure we catch stdio events like closing the stdin file descriptor. Otherwise those events will go undetected until the next stream write.
Fixes: #25131