-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
process: make serialization function configurable #6400
Conversation
By default process.send() serializes messages using vanilla JSON.stringify(). This commit makes the serialization function configurable. Refs: nodejs#6300
LGTM-ish. The code changes themselves LGTM but:
|
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); |
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.
Not that it matters to much, but assert
and cp
could be required only in the parent.
I thought about the deserializer configuration, but no good ideas came to mind. Theoretically, you could specify a different serializer for every call to |
Nothing in this PR, code, comments, or the docs suggests a reason to do this. The input is fixed, the output is fixed (must be JSON)... but you want to replace the built-in serializer because.... why? |
My reason is that forcing Additionally, as brought up in #6300 and other places, the |
LGTM. Good first step. Also utilizing .stringify() features is very effective for chopping of data, see here. |
What's the point if deserializer is still the same? One can just define |
I agree, the deserializer should be configurable. Giving it some thought. |
|
||
If Node.js was not spawned with an IPC channel, `process.send()` will be undefined. | ||
If Node.js was not spawned with an IPC channel, `process.send()` will be | ||
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.
Can you please include some detail about the serializer
function. What arguments will be passed? What should it return? What happens if it throws? If it shouldn't throw, how should it handle errors? etc.
This stuff starts to get very complicated with configurable serializers and deserializers but it can also be very handy. If you're going to go this route, I would recommend using a simple binary framing for the messages. A small header frame would be used to identify the serializer that was used so that an appropriate deserializer can be selected on the receiving end. Then use a length prefix for the actual payload. If the receiving end gets a message it cannot deserialize, we would need to decide if that's an error or not. Also, would we want to require the messages to still be JSON or at least text based? One could easily imagine someone wanting to send a fully binary message, in which case the serializer could return a I'm certainly not against allowing for multiple serializers we just need to be deliberate about how we do so (and about just how much freedom we give to those). |
Are you continuing somewhere else? |
Not right now. |
@cjihrig I think deserialiser should be a node argv option. Something like node --ipc-serialiser=module-name app.js ... It should to specify node module which realises serialisation interface with methods serialise and deserialise. Or better to add |
There already is the |
@addaleax Shame on me 😕 ... Yep that's what I was talking about. Thanks. |
@rumkin the |
@cjihrig But I can require such module which will register serialiser. Registration could be made with method |
Checklist
Affected core subsystem(s)
process
Description of change
By default
process.send()
serializes messages using vanilla JSON.stringify(). This commit makes the serialization function configurable.Refs: #6300