-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Handing spawn() stdio as socket wont duplex properly #15714
Comments
@devinivy - is this still outstanding? From your description, I understood upto the point you were saying that the child data reaches upto the socket in the server. Then what? where else it should flow as per your expectation? |
I just tried this on node v8.11.1 and got the same results. After coming back to this issue after some time, I can see how it's a little confusing—sorry for that. I will try to be a little clearer. I was trying to author a passthrough-style stream that can be used with As such, I expected the output of the program to be,
Instead I only get the first line, which is very hard for me to explain to myself. Especially because if I write directly to // ...
makePassThrough((err, stdout) => {
if (err) {
throw err;
}
stdout.on('data', (data) => console.log('subproc stdout saw data:', data.toString()));
stdout.write('is anybody out there?');
});
/* Program outputs the following,
$ node index.js
server sock saw data: is anybody out there?
subproc stdout saw data: is anybody out there?
# Does not exit
*/ Does this provide some more useful context? |
thanks. one or two iterations and we should be good to understand each other! so: no data being available through: stdout.on('data', (data) => console.log('subproc stdout saw data:', data.toString())) is this the problem? |
Yes, exactly! I would expect that line to log |
Here is the relevant sections in the strace dump:
I guess the summary of the puzzle is, where is fd 9 pointing to? |
I installed 2 handlers: one on the socket in question and one on subproc.stdout, the socket that acts as the parent end of the IPC pipe thus: stdout.on('data', dh1)
subproc.stdout.on('data', dh2) and the trace revealed this: bind socket 0x2cdc5bb49dc9 with data handler dh1:
emit 'data' on socket 0x2cdc5bb4a501. No handler for this socket, so no handler invoked, the stream is read again, and chunk is ignored.
bind socket 0x10312b449dc9 with data handler dh2:
emit 'data' on socket 0x10312b44a501 that is still different from the one for which we istalled dh2, but the handler seem to have invoked as if the data handler is added on that socket!
Something beyond my understanding, so /cc @nodejs/streams to see what is going on: the precreated socket is not used for IPC is understood, but how do we link it with the active socket it is the key requriement here. |
I still do not understand what is the issue and what are you trying to achieve. |
so looks like pre-rcreated stream looses its association with the underlying socket and / or the event handlers. The |
I'm still lost why we should support such a thing. It seems very fragile, and very prone to breakage.
I think the spawned process hold a reference to the handle/fd, and when that gets collected that is freed. Please verify this.
This is normal. If you call |
I attempted this for testing purposes. I was authoring a CLI tool and wanted to mock stdin/stdout for my tests. One of my CLI commands uses
Is this to say that the program's execution makes sense specifically if the stream errored? Is the caveat I missed simply that you can't pass a |
I agree that we should document that this is not really feasible. |
Hi, @BridgeAR a question, is this issue still open? I would like to start collaborating on this project. |
Hi, I'm looking to contribute to this project. Is documentation still needed for this issue, considering that the previous pull request was closed? |
I do not know if this issue is no longer a thing or is necessary. But i made a PR to update the documentation to reflect the discovery found in this thread and sent it out. Please review and request changes if needed 😊🤟🏿 |
PR-URL: nodejs#55322 Fixes: nodejs#15714 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: nodejs#55322 Fixes: nodejs#15714 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
I'm trying to implement a sort of
PassThrough
-style stream that can be used as mock stdio forChildProcess.spawn()
.PassThrough
itself isn't appropriate because it doesn't have a file descriptor. So I'm doing this by creating a socket that speaks to an echo server. What I'm finding is that the server receives the data and successfully pipes it, but the passthrough socket never seems to receive it.I've poked around the node internals a bit to figure-out why, but I don't have much to share at this time. It looks like
spawn()
may create another socket that's readable and not writable, and uses the socket I passed as its handle [here]. But my socket remains readable and writable as I would expect, so I still can't explain the behavior!Possibly related to #9413. Here's some code to reproduce the issue and play with.
For my purposes I'm all set– I can use
stdio: 'pipe'
and pipe the process's stdio thru actual passthrough streams. This is still a curiosity, though!The text was updated successfully, but these errors were encountered: