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

Projects
None yet
3 participants
@cjihrig
Contributor

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

return handle;
},
postSend: function(handle) {
postSend: function(handle, options) {
// Close the Socket handle after sending it

This comment has been minimized.

@jasnell

jasnell Feb 17, 2016

Member

very minor nit: wouldn't it be slightly more efficient to:

if (options.keepOpen) return;
if (handle) handle.close();

/cc @bnoordhuis

@jasnell

jasnell Feb 17, 2016

Member

very minor nit: wouldn't it be slightly more efficient to:

if (options.keepOpen) return;
if (handle) handle.close();

/cc @bnoordhuis

This comment has been minimized.

@cjihrig

cjihrig Feb 18, 2016

Contributor

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.

@cjihrig

cjihrig Feb 18, 2016

Contributor

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.

This comment has been minimized.

@jasnell

jasnell Feb 19, 2016

Member

ok, good enough for me.

@jasnell

jasnell Feb 19, 2016

Member

ok, good enough for me.

@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Feb 17, 2016

Member

LGTM

Member

jasnell commented Feb 17, 2016

LGTM

@cjihrig

This comment has been minimized.

Show comment
Hide comment
@cjihrig

cjihrig Feb 20, 2016

Contributor

@bnoordhuis would you mind taking a look at this?

Contributor

cjihrig commented Feb 20, 2016

@bnoordhuis would you mind taking a look at this?

@bnoordhuis

View changes

Show outdated Hide outdated lib/internal/child_process.js
@bnoordhuis

View changes

Show outdated Hide outdated lib/internal/child_process.js
@bnoordhuis

View changes

Show outdated Hide outdated lib/internal/child_process.js
@bnoordhuis

View changes

Show outdated Hide outdated lib/internal/child_process.js
});
server.listen(common.PORT, () => {
const socket = net.connect(common.PORT, common.localhostIPv4);

This comment has been minimized.

@bnoordhuis

bnoordhuis Feb 21, 2016

Member

Call socket.setEncoding('utf8') if you're going to do string concatenation.

@bnoordhuis

bnoordhuis Feb 21, 2016

Member

Call socket.setEncoding('utf8') if you're going to do string concatenation.

@bnoordhuis

View changes

Show outdated Hide outdated test/parallel/test-child-process-send-type-error.js
@cjihrig

This comment has been minimized.

Show comment
Hide comment
@cjihrig

cjihrig Feb 21, 2016

Contributor

@bnoordhuis nits addressed.

Contributor

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;

This comment has been minimized.

@bnoordhuis

bnoordhuis Feb 21, 2016

Member

Just noting that this allows a send(message, callback, options) signature.

@bnoordhuis

bnoordhuis Feb 21, 2016

Member

Just noting that this allows a send(message, callback, options) signature.

@bnoordhuis

This comment has been minimized.

Show comment
Hide comment
@bnoordhuis

bnoordhuis Feb 21, 2016

Member

LGTM with a comment.

Member

bnoordhuis commented Feb 21, 2016

LGTM with a comment.

@cjihrig

This comment has been minimized.

Show comment
Hide comment
@cjihrig

cjihrig Feb 22, 2016

Contributor

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/

Contributor

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/

cjihrig added some commits Feb 16, 2016

child_process: support options in send()
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>
child_process: add keepOpen option to send()
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>

@cjihrig cjihrig merged commit e854f60 into nodejs:master Feb 22, 2016

@cjihrig cjihrig deleted the cjihrig:send-opts branch Feb 22, 2016

pavelfeldman added a commit to pavelfeldman/node that referenced this pull request Feb 24, 2016

child_process: support options in send()
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>

pavelfeldman added a commit to pavelfeldman/node that referenced this pull request Feb 24, 2016

child_process: add keepOpen option to send()
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 was referenced Mar 1, 2016

Fishrock123 added a commit that referenced this pull request Mar 8, 2016

child_process: support options in send()
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 added a commit that referenced this pull request Mar 8, 2016

child_process: add keepOpen option to send()
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

child_process: support options in send()
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 added a commit that referenced this pull request Mar 8, 2016

child_process: add keepOpen option to send()
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

2016-03-08, Version 5.8.0 (Stable)
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

2016-03-08, Version 5.8.0 (Stable)
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