Skip to content
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

Merged
merged 2 commits into from
Feb 22, 2016

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Feb 17, 2016

This PR adds an options argument to child_process.send() and process.send(). The second commit adds a keepOpen option that allows net.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 optional sendHandle 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

@jasnell jasnell added semver-minor PRs that contain new features and should be released in the next minor version. child_process Issues and PRs related to the child_process subsystem. labels Feb 17, 2016

return handle;
},

postSend: function(handle) {
postSend: function(handle, options) {
// Close the Socket handle after sending it
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

@jasnell
Copy link
Member

jasnell commented Feb 17, 2016

LGTM

@cjihrig
Copy link
Contributor Author

cjihrig commented Feb 20, 2016

@bnoordhuis would you mind taking a look at this?

socket.server._connections--;
if (!options.keepOpen)
socket.server._connections--;

Copy link
Member

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.

@cjihrig
Copy link
Contributor Author

cjihrig commented Feb 21, 2016

@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;
Copy link
Member

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.

@bnoordhuis
Copy link
Member

LGTM with a comment.

@cjihrig
Copy link
Contributor Author

cjihrig commented Feb 22, 2016

Thanks for the reviews. Addressed your most recent comment (set options = undefined in that case).

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>
@cjihrig cjihrig merged commit e854f60 into nodejs:master Feb 22, 2016
@cjihrig cjihrig deleted the send-opts branch February 22, 2016 17:03
This was referenced Mar 1, 2016
Fishrock123 pushed a commit that referenced this pull request Mar 8, 2016
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>
Fishrock123 pushed a commit that referenced this pull request Mar 8, 2016
This option allows an instance of net.Socket to be kept open in
the sending process.

Fixes: #4271
PR-URL: #5283
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fishrock123 pushed a commit that referenced this pull request Mar 8, 2016
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>
Fishrock123 pushed a commit that referenced this pull request Mar 8, 2016
This option allows an instance of net.Socket to be kept open in
the sending process.

Fixes: #4271
PR-URL: #5283
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fishrock123 added a commit that referenced this pull request Mar 8, 2016
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
Fishrock123 added a commit to Fishrock123/node that referenced this pull request Mar 9, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants