-
Notifications
You must be signed in to change notification settings - Fork 275
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
max length / max size of message field between parent/child #1265
Comments
Not sure if it is mentioned in the documentation. Probably it depends on the operating system. On linux it seems that the max length is |
@advanceddeveloper - what happens if we give more than that? Does it truncate or send in iterations? I guess the later. @ORESoftware - I guess you mean the size that can be sent in one chunk right? As these are normal sockets that are piped, I don't think there is any Node.js imposed limit, instead chunking occurs, at the OS level. |
Of course it splits the buffer and send in iterations, that is also the purpose of the
I am pretty sure @ORESoftware is asking for the size of one chunk (not the whole buffer from the other process), so it seems that my assumption "probably it depends on the operating system." is right... |
I forgot to mention that even if you know the limit of the chunk size, it is not guaranteed that OS will not split it up in even smaller chunks. If you want to send several stringified JSONs from one process to another, you should somehow store previous chunks and concatenate results, and also detect boundaries of adjacent json strings. Here is a very simple example how you can make it work no matter how small chunk size is: main-process.js'use strict';
var cp = require('child_process');
var proc = cp.spawn('node', ['./child-process.js']);
proc.stdout.pipe(process.stdout);
proc.stdin.write(JSON.stringify([1, 2, 3, 4, 5]));
proc.stdin.write(JSON.stringify({key1: 'value1', key2: ['value2']}));
proc.stdin.write(JSON.stringify({numeric: 123.45}));
proc.stdin.write('{"a":');
proc.stdin.write('"b"}[1]');
proc.stdin.end(); child-process.js'use strict';
var data = Buffer.alloc(0);
process.stdin.on('data', d => {
var index = data.length + 1;
data = Buffer.concat([data, d]);
while(index !== data.length + 1){
var str = data.slice(0, index).toString('utf8');
var valid = false;
var json;
try{
json = JSON.parse(str);
valid = true;
}catch{}
if(!valid){
index++;
continue;
}
console.log('RECEIVED JSON:');
console.log(JSON.stringify(json));
console.log('');
data = data.slice(index);
index = 0;
}
}); And here is the output: OutputRECEIVED JSON:
[1,2,3,4,5]
RECEIVED JSON:
{"key1":"value1","key2":["value2"]}
RECEIVED JSON:
{"numeric":123.45}
RECEIVED JSON:
{"a":"b"}
RECEIVED JSON:
[1] |
Yeah in the original question, I am not talking about the socket, I am talking about |
Which The first one can be large up to |
Well yeah |
not sure if there is anything outstanding here - @ORESoftware ? |
closing as answered, please let me know if anything is outstanding here. |
I am on Node.js version 9.
I am wondering, what is the max size of the message field
'm'
?how big can
m
be in size? I am thinking of putting some JSON data in there.The text was updated successfully, but these errors were encountered: