0

Using the following code in NodeJs:

const { fork } = require('child_process');
const thread = fork(path.join(__dirname, '/thread.js'));
thread.on('message', (results) => {
  console.log('RES', results.length);
  if (results.error) {
    res.send({ error: true, message: results.message });
    return;
  }
  res.send(results.data);
});
thread.on('error', (err) => {
  console.log(err);
});
thread.send({ data: JSON.stringify(dataToProcess) });
thread.on('exit', () => {
  if (thread) {
    thread.kill();
    return;
  }
});

When sending larger (1.5mb) messages from child to parent, it doesn't send anything. Smaller messages are sent without issue. Is there some hard limit? If so, can it be increased?

Testing different payload sizes now:

1mb - fails to send

0.5mb - fails

0.2mb - fails

0.15mb - ok

0.1mb - ok

On windows its OK....linux seems to have a limit

pb46
  • 13
  • 3
  • Does this answer your question? [Node.js forked child return message limit, and ways around it](https://stackoverflow.com/questions/26787279/node-js-forked-child-return-message-limit-and-ways-around-it) – lifeisfoo Apr 01 '21 at 09:52
  • Did see that, but didn't resolve it. Testing different payload sizes now: 1mb - fails to send 0.5mb - fails 0.1mb - ok. On windows its ok....linux seems to have a limit – pb46 Apr 01 '21 at 09:55
  • See https://github.com/nodejs/node/issues/8249. Probably you need to open an issue in the nodejs repository, but I see many closed issues like this with a "cannot reproduce" message. – lifeisfoo Apr 01 '21 at 10:17

1 Answers1

0

I wasn't able to figure it out, but I did change the fork to web-workers and it seemed to send out larger payloads. I don't know the full repercussions yet, but I'll continue to monitor it

pb46
  • 13
  • 3