Node.js child process exits with SIGTERM
Asked Answered
M

1

9

I'm spawning a child process using Node 6.9.

const child = require('child_process').execFile('command', args); 
child.stdout.on('data', (data) => {
    console.log('child:', data);
});
child.stderr.on('data', (data) => {
    console.log('child:', data);
});
child.on('close', (code, signal) => {
    console.log(`ERROR: child terminated. Exit code: ${code}, signal: ${signal}`);
});

My child process runs for ~1m 30s but then I get this output from my Node.js program:

ERROR: child terminated. Exit code: null, signal: SIGTERM

What terminates my child process and why?

Edit: I've added killSignal: 'SIGILL' as an option.

var child = require('child_process').execFile('geth', args, { killSignal: 'SIGILL'}); 

Now, I get this:

ERROR: go-ethereum terminated. Exit code: 2, signal: null
Matthia answered 13/4, 2017 at 21:18 Comment(4)
Does “standalone” mean inside the container but not spawned by Node, or outside the container but spawned by Node?Devindevina
Hi Ryan, sorry I made it more clear. Inside the container but not spawned by NodeMatthia
I don’t suppose args has a timeout property? If you pass Object.assign({}, args, {killSignal: 'SIGILL'}), does the signal change?Devindevina
I now get ERROR: go-ethereum terminated. Exit code: 2, signal: null. See above.Matthia
M
12

I found the problem and a solution.

From https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

maxBuffer largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200*1024)

I can set the maxBuffer option higher.

childProcess.execFile('geth', args, { maxBuffer:  400 * 1024});

It seems you can't disable the maxBuffer option, not even by setting it to 0. But it seems to be on purpose.

Matthia answered 17/4, 2017 at 22:58 Comment(2)
I think the same thing happened to me when I ran a program with "progress notifications" as a subprocess. After running for a while, Node keeled. It seems tricky to estimate how big the buffer size should be. It seems to me that a good general solution is to avoid running programs that log too much information.Serology
Yeah, it helps. But better use the more appropriate function – spawn (instead of execFile). See: medium.com/edge-coders/-e69498fe970aNovanovaculite

© 2022 - 2024 — McMap. All rights reserved.