-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
8a3b2e1
to
6e47903
Compare
doc/api/child_process.md
Outdated
@@ -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]. |
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.
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.
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.
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).
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.
Also the MDN documentation doesn't mention the circular reference error...:/ hmm
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.
Nit: The comma after sent
should be a period. See notes at...
can be its own sentence.
doc/api/child_process.md
Outdated
@@ -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 |
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 would just use the exact same text as suggested above for this part.
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.
Nit: this
-> This
doc/api/process.md
Outdated
* `sendHandle` {Handle object} a [`net.Socket`][] or [`net.Server`][] object, or | ||
undefined. | ||
|
||
*Note*: since the message goes through JSON serialization and parsing, it might |
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.
Ditto.
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.
Nit: since
-> Since
doc/api/process.md
Outdated
@@ -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 |
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.
Ditto.
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.
Nit: this
-> This
doc/api/process.md
Outdated
* `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 |
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.
Identical nit as above about comma and see notes
.
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 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.
doc/api/child_process.md
Outdated
@@ -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 |
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.
JSON.stringify()
is already in this list of links in both of these files.
doc/api/process.md
Outdated
@@ -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 |
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.
please keep the refs sorted
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. |
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.
6e47903
to
9d99868
Compare
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 |
Landed in ba5a668 (I felt free to land this due to no response from @joyeecheung since a month) |
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]>
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]>
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]>
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]>
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), orvcbuild test
(Windows) passesAffected core subsystem(s)
doc, process, child_process