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

doc: note caveats in process message serialization #12963

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

The message sent using process.send() goes through JSON
serialization and parsing, which could lead to surprising behaviors.
This commit elaborate a bit more on this and add a link to
the notes about these caveats in the ECMAScript specification.

Refs: #12497

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc, process, child_process

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label May 11, 2017
@joyeecheung joyeecheung added child_process Issues and PRs related to the child_process subsystem. process Issues and PRs related to the process subsystem. labels May 11, 2017
@@ -849,6 +849,10 @@ added: v0.5.9
The `'message'` event is triggered when a child process uses [`process.send()`][]
to send messages.

*Note*: since the message goes through JSON serialization and parsing, it might
not be the same as what is originally sent, see notes of
[the `JSON.stringify()` specification][`JSON.stringify` spec].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps simplify the link and adjust some of the wording here... for example:

*Note*: since the message is transmitted as JSON, not all values may be transferred as-is. See the documentation for [`JSON.stringify()`][] for more details.

Where the JSON.stringify() link goes to MDN instead (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description), which IMHO has a more readable description of when/how values are converted.

Copy link
Member Author

@joyeecheung joyeecheung May 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MDN documentation doesn't mention the Nan/Infinity -> null thing which I think is one of the surprising behaviors..the link is not about the serialization process, but rather, the caveats, which are described in the notes of the ECMA spec (although I cannot find a direct anchor to those notes, so I use the link to the method instead).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the MDN documentation doesn't mention the circular reference error...:/ hmm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The comma after sent should be a period. See notes at... can be its own sentence.

@@ -996,6 +1000,13 @@ i.e. when using [`child_process.fork()`][]), the `child.send()` method can be
used to send messages to the child process. When the child process is a Node.js
instance, these messages can be received via the [`process.on('message')`][] event.

*Note*: this function uses [`JSON.stringify()`][] internally to serialize the
Copy link
Contributor

@mscdex mscdex May 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use the exact same text as suggested above for this part.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this -> This

* `sendHandle` {Handle object} a [`net.Socket`][] or [`net.Server`][] object, or
undefined.

*Note*: since the message goes through JSON serialization and parsing, it might
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since -> Since

@@ -1429,8 +1432,12 @@ used to send messages to the parent process. Messages will be received as a
If Node.js was not spawned with an IPC channel, `process.send()` will be
`undefined`.

*Note*: This function uses [`JSON.stringify()`][] internally to serialize the
`message`.*
*Note*: this function uses [`JSON.stringify()`][] internally to serialize the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this -> This

* `sendHandle` {Handle object} a [`net.Socket`][] or [`net.Server`][] object, or
undefined.

*Note*: since the message goes through JSON serialization and parsing, it might
not be the same as what is originally sent, see notes of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical nit as above about comma and see notes.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the existing messaging (Note: this function uses [JSON.stringify()][] internally to serialize the message.) is good. The message should probably be moved to a better location in the send() docs though.

I don't think we should explain too much about how stringify() works, when we are linking to it already.

@@ -1258,6 +1268,7 @@ to `stdout` although there are only 4 characters.
[`child_process.fork()`]: #child_process_child_process_fork_modulepath_args_options
[`child_process.spawn()`]: #child_process_child_process_spawn_command_args_options
[`child_process.spawnSync()`]: #child_process_child_process_spawnsync_command_args_options
[`JSON.stringify` spec]: https://tc39.github.io/ecma262/#sec-json.stringify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify() is already in this list of links in both of these files.

@@ -1836,6 +1843,7 @@ cases:
[`console.error()`]: console.html#console_console_error_data_args
[`console.log()`]: console.html#console_console_log_data_args
[`end()`]: stream.html#stream_writable_end_chunk_encoding_callback
[`JSON.stringify` spec]: https://tc39.github.io/ecma262/#sec-json.stringify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the refs sorted

@BridgeAR
Copy link
Member

Ping @joyeecheung this needs a rebase and the comments still need to be addressed

@Trott
Copy link
Member

Trott commented Aug 27, 2017

Ping @joyeecheung this needs a rebase and the comments still need to be addressed

@joyeecheung I'm happy to push a commit for fixes for my nits if you'd like. Just let me know.

@BridgeAR
Copy link
Member

Ping @Trott do you want to follow up on this? I would otherwise close this.

The message sent using process.send() goes through JSON
serialization and parsing, which could lead to surprising behaviors.
This commit elaborate a bit more on this and add a link to
the notes about these caveats in the ECMAScript specification.
@Trott
Copy link
Member

Trott commented Sep 20, 2017

Ping @Trott do you want to follow up on this? I would otherwise close this.

I rebased, resolved conflicts, fixed all nits, and pushed back up to Joyee's branch. I think this is ready to land.

@cjihrig Can you review and clear your request for changes if this addresses your concerns? I'm not sure if the new wording I settled on is OK by you or not.

@joyeecheung Can you review and confirm that what I've done here meets your intentions?

@nodejs/documentation PTAL

@BridgeAR
Copy link
Member

Landed in ba5a668

(I felt free to land this due to no response from @joyeecheung since a month)

@BridgeAR BridgeAR closed this Sep 22, 2017
BridgeAR pushed a commit that referenced this pull request Sep 22, 2017
The message sent using process.send() goes through JSON
serialization and parsing, which could lead to surprising behaviors.
This commit elaborate a bit more on this and add a link to
the notes about these caveats in the ECMAScript specification.

PR-URL: #12963
Refs: #12497
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 23, 2017
The message sent using process.send() goes through JSON
serialization and parsing, which could lead to surprising behaviors.
This commit elaborate a bit more on this and add a link to
the notes about these caveats in the ECMAScript specification.

PR-URL: nodejs/node#12963
Refs: nodejs/node#12497
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
jasnell pushed a commit that referenced this pull request Sep 25, 2017
The message sent using process.send() goes through JSON
serialization and parsing, which could lead to surprising behaviors.
This commit elaborate a bit more on this and add a link to
the notes about these caveats in the ECMAScript specification.

PR-URL: #12963
Refs: #12497
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Sep 29, 2017
The message sent using process.send() goes through JSON
serialization and parsing, which could lead to surprising behaviors.
This commit elaborate a bit more on this and add a link to
the notes about these caveats in the ECMAScript specification.

PR-URL: #12963
Refs: #12497
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Oct 3, 2017
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. doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants