-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Allow options to be provided to child_process.send() #5283
Conversation
|
||
return handle; | ||
}, | ||
|
||
postSend: function(handle) { | ||
postSend: function(handle, options) { | ||
// Close the Socket handle after sending it |
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.
very minor nit: wouldn't it be slightly more efficient to:
if (options.keepOpen) return;
if (handle) handle.close();
/cc @bnoordhuis
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 don't really like the idea of returning from the function early if options.keepOpen
is true
. That could require more refactoring if we ever decided to add more functionality here. It also makes the code less readable IMO. Also, 100% of legacy code and probably the majority of new code would have keepOpen = false
, meaning that it would have to run two separate if
statements instead of only checking keepOpen
if handle
is truthy.
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.
ok, good enough for me.
LGTM |
@bnoordhuis would you mind taking a look at this? |
socket.server._connections--; | ||
if (!options.keepOpen) | ||
socket.server._connections--; | ||
|
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.
Style nit: superfluous blank line.
@bnoordhuis nits addressed. |
@@ -498,13 +502,22 @@ function setupChannel(target, channel) { | |||
}); | |||
}); | |||
|
|||
target.send = function(message, handle, callback) { | |||
target.send = function(message, handle, options, callback) { | |||
if (typeof handle === 'function') { | |||
callback = handle; | |||
handle = undefined; |
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.
Just noting that this allows a send(message, callback, options)
signature.
LGTM with a comment. |
Thanks for the reviews. Addressed your most recent comment (set CI is yellow. One unrelated ARM failure on a flakey test. https://ci.nodejs.org/job/node-test-pull-request/1720/ |
This commit adds an options object to process.send(). The same object is propagated to process._send(), the _handleQueue, and the send() and postSend() functions of the handle converter. Fixes: nodejs#4271 PR-URL: nodejs#5283 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This option allows an instance of net.Socket to be kept open in the sending process. Fixes: nodejs#4271 PR-URL: nodejs#5283 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit adds an options object to process.send(). The same object is propagated to process._send(), the _handleQueue, and the send() and postSend() functions of the handle converter. Fixes: #4271 PR-URL: #5283 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit adds an options object to process.send(). The same object is propagated to process._send(), the _handleQueue, and the send() and postSend() functions of the handle converter. Fixes: #4271 PR-URL: #5283 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Notable changes: * child_process: “send()” now accepts an options parameter (cjihrig) #5283 - Currently the only option is “keepOpen”, which keeps the underlying socket open after the message is sent. * constants: “ENGINE_METHOD_RSA” is now correctly exposed (Sam Roberts) #5463 * Fixed two regressions which originated in v5.7.0: - http: Errors inside of http client callbacks now propagate correctly (Trevor Norris) #5591 - path: Fixed normalization of absolute paths (Evan Lucas) #5589 * repl: “start()” no longer requires an options parameter (cjihrig) #5388 * util: Improved “format()” performance 50-300% (Evan Lucas) #5360 PR-URL: #5559
Notable changes: * child_process: “send()” now accepts an options parameter (cjihrig) nodejs#5283 - Currently the only option is “keepOpen”, which keeps the underlying socket open after the message is sent. * constants: “ENGINE_METHOD_RSA” is now correctly exposed (Sam Roberts) nodejs#5463 * Fixed two regressions which originated in v5.7.0: - http: Errors inside of http client callbacks now propagate correctly (Trevor Norris) nodejs#5591 - path: Fixed normalization of absolute paths (Evan Lucas) nodejs#5589 * repl: “start()” no longer requires an options parameter (cjihrig) nodejs#5388 * util: Improved “format()” performance 50-300% (Evan Lucas) nodejs#5360 PR-URL: nodejs#5559
This PR adds an
options
argument tochild_process.send()
andprocess.send()
. The second commit adds akeepOpen
option that allowsnet.Socket
instances to be kept open in multiple processes.One limitation of the current implementation is that the new
options
argument can only be specified if the optionalsendHandle
argument is also provided. It's an unfortunate side effect of allowing multiple optional arguments of the same data type consecutively in function arguments. It can be worked around by duplicating code in_send()
, but I'd rather save that for a semver-major change.Closes #4271