-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: fire close event from stdio #22892
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { spawn } = require('child_process'); | ||
const net = require('net'); | ||
|
||
const server = net.createServer((conn) => { | ||
conn.on('close', common.mustCall()); | ||
|
||
spawn(process.execPath, ['-v'], { | ||
stdio: ['ignore', conn, 'ignore'] | ||
}).on('close', common.mustCall()); | ||
}).listen(common.PIPE, () => { | ||
const client = net.connect(common.PIPE, common.mustCall()); | ||
client.on('data', () => { | ||
client.end(() => { | ||
server.close(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So … the code above (https://github.com/nodejs/node/pull/22892/files#diff-f45eb699237c2e38dc9b49b588933c11R923) reads like
stdio
could be:handle
property which is a native stream handle_handle
property which is a native stream handleThe path that is typically taken for e.g.
net.Socket
s would be the third one, I think. We should probably look into deprecating at least the first two, but … all that’s a different story and not really for this PR.What matters is that
stdio
does not need to be any kind of particular object; most of the time, it’s anet.Socket
or similar, but it could also just be{ handle: someNativeHandle }
. Even though that’s a bad idea imo, the code above points to this being a possibility. This means that thestream._stdio.emit()
call above might fail, becauseemit()
might not be available?I guess a simple solution would be to turn the
if (stream._stdio) {
conditional intoif (stream._stdio && typeof stream._stdio.emit === 'function') {
?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 see. I will fix other PR.
I came up with a way when object is pushed. How about this?
Should it be judged when
emit()
?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 how about
if (stream._stdio instanceof EventEmitter)
?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.
@koh110 I’m not sure.
instanceof EventEmitter
is probably fine, too?I would prefer for the
_stdio
property to be present consistently, though – either it’s always there or always missing.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.
@addaleax Yeah, you right. I completely agree. I was wrong.
I feel that
if (stream._stdio && stream._stdio instanceof EventEmitter) {
is more meaningful thanif(stream._stdio && typeof stream._stdio.emit === 'function') {
.EventEmitter
may be changed toWritableStream
. What do you think about it?