child_process: add callback parameter to .send()#2620
Conversation
|
Looks great to me, two concerns: 1) the FIXME and 2) the ref/unref timing and potential for it to go below zero, obviously it shouldn't and I'm not suggesting your code has a way to do this but in the interests of defensiveness I wonder if the decrement shouldn't have a guard for I'm happy with this going into v4, the doc changes are appreciated too. I'm also impressed this actually works on Windows! Some kind of black magic. |
|
@bnoordhuis how does this interact with windows, where afaik you don't get this return info? |
There was a problem hiding this comment.
While here mind fixing placement of the first [?
|
Known issues in each changelog says:
Does this mean that the intention is to keep it asynchronous? (in which case it's no longer a known issue, but rather BC breakage) |
|
yes and yes |
|
Thanks 👍 |
There was a problem hiding this comment.
Any reason not to just nextTick() this right now?
There was a problem hiding this comment.
None that I can think of but it wouldn't be the first time a seemingly innocuous looking change breaks something. If we can get consensus, I'll change it.
There was a problem hiding this comment.
After looking through the code base, there are actually many places where errors are emitted on the same tick. Maybe the FIXME should just be removed instead.
That would be a logic error. I can add an assert if you want. Incorporated @trevnorris's suggestions, PTAL (and good one on the |
There was a problem hiding this comment.
This impacts the cluster API and process API, which surface .send().
I assume process will now have an error event which can be emitted if send fails, and node will crash if it isn't listened on?
For users of cluster, if they fail to listen on worker.process.on('error', ..., the master will crash? Or will you re-emit from the process object onto the worker object?
There was a problem hiding this comment.
There is no change in functionality - what's described here is the the current behavior, it just wasn't documented.
There was a problem hiding this comment.
I thought send() after disconnect resulted in an error being thrown, not an error emitted, currently.
There was a problem hiding this comment.
It emits an error event, but a synchronous one. So yes, if you don't have an error listener, it's effectively throwing an exception. That behavior is (for better or worse) maintained in this patch.
|
Nothing else from me. LGTM. |
Add an optional callback parameter to `ChildProcess.prototype.send()` that is invoked when the message has been sent. Juggle the control channel's reference count so that in-flight messages keep the event loop (and therefore the process) alive until they have been sent. `ChildProcess.prototype.send()` and `process.send()` used to operate synchronously but became asynchronous in commit libuv/libuv@393c1c5 ("unix: set non-block mode in uv_{pipe,tcp,udp}_open"), which landed in io.js in commit 07bd05b ("deps: update libuv to 1.2.1").
|
https://ci.nodejs.org/job/node-test-commit-arm/434/nodes=armv7-wheezy/tapTestReport/ How the hell is that failing here all of a sudden?? |
|
that output is normal output for eval_messages.js and doesn't necessarily indicate why it's failing, something else is going on to make it fail and the output isn't being very helpful |
|
Can we just try CI again to see if we get lucky and it passes? Would be nice to get this landed. |
|
Could the failure be related to this PR, or is that test just flaky? |
|
@orangemocha Believe it's just a flaky test. |
|
Okay, I opened #2648 to mark it so. |
|
Overall the change LGTM. Where are things at with regards to the failing CI? Were the failures unrelated? |
Add an optional callback parameter to `ChildProcess.prototype.send()` that is invoked when the message has been sent. Juggle the control channel's reference count so that in-flight messages keep the event loop (and therefore the process) alive until they have been sent. `ChildProcess.prototype.send()` and `process.send()` used to operate synchronously but became asynchronous in commit libuv/libuv@393c1c5 ("unix: set non-block mode in uv_{pipe,tcp,udp}_open"), which landed in io.js in commit 07bd05b ("deps: update libuv to 1.2.1"). Fixes: #760 PR-URL: #2620 Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com> Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Add an optional callback parameter to
ChildProcess.prototype.send()that is invoked when the message has been sent.
Juggle the control channel's reference count so that in-flight messages
keep the event loop (and therefore the process) alive until they have
been sent.
ChildProcess.prototype.send()andprocess.send()used to operatesynchronously but became asynchronous in commit libuv/libuv@393c1c5
("unix: set non-block mode in uv_{pipe,tcp,udp}_open"), which landed
in io.js in commit 07bd05b ("deps: update libuv to 1.2.1").
Fixes: #760
R=@rvagg - note that I'm on holiday and may not be able to respond quickly if at all.
CI: https://jenkins-iojs.nodesource.com/job/node-test-pull-request/211/