Recently, I was facing issue with Node.jschild_process.exec
which return exit code null. Here are some insights and how I solved it.
We use to run python/psql scripts from our node.js application using child_process.exec(command[, options][, callback])
. These executions use to run successfully for small files (lesser LOC and logs).
I faced an issue, where one of the script execution stopped abruptly with exit code null.
I initially didn’t bother about exit code. I was looking through the logs (3000+ lines of logs), I couldn’t find anything fishy.
I thought, the problem might be with the script, so, was carefully going through script(3000+ LOC), but I ended up finding nothing. Then, I thought, let’s run the script directly from the command line, instead of triggering from node.js application (to find the issue).
When I ran the script, it ran successfully with exit code 0. This made me to scratch my head , since I expected this script execution to fail.
Generally, scripts triggered from our node.js application runs successfully, but this script was exceptional. After few hours of spending time and thinking, I looked into the logs again. This time, the execution exit code null was rolling my eyes.
I started searching online with node.js child_process.exec with exit code null. After spending sometime, I ended up with maxBuffer option.
When an execution (which we run using node.js child_process.exec) generates more logs, node.js runs out of buffer memory and couldn’t handle the execution and stops abruptly.
Here is the reference link for more details on child_process.exec and maxBuffer.
Then, I set this maxBuffer option to 10486750(10mb) in my code and things got resolved. Here is the sample code which triggers script execution.