Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
Node async operations on child_process are not ending

I have a little script that executes a childprocess using execFile. This child process is a node script too that runs async operations but it seems like that the async are never ending so the terminal and all the processes are on hold.

This is the main script that runs the execFile for the child process:

fs.readdir(directoryPath, function(err, files) {
if (err) console.log(`Error: ${err}`);

files.map((file) => {
    execFile(`node`, ["updater.js", "BMW", file], (error, stdout, stderr) => {
        if (error) {
            red(`error: ${error.message}`);
            return;
        }

        if (stderr) {
            red(`stderr: ${stderr}`);
            return;
        }

        console.log(stdout);
    });
 });
});

And this is the node script executed as child process:

const args = process.argv.slice(2);
const brand = args[0];
const model = args[1];

const data = readJSON(`./json-export/${brand}/${model}`);
const generations = data.generations;

const generationsDB = await getGenerationsByModelAndBrand(brand, model);
console.log(generationsDB);

generations.map((generation) => {
   const lastModification =
       generation.modifications.modification[
           generation.modifications.modification.length - 1
        ];

  console.log(lastModification);
});

All the code works if I comment the const generationsDB line and the next console.log. If not when execution hits to the async request the execution gets stucked there. Tested the getGenerationsByModelAndBrand on the main script and works with no issue.

The getGenerationsByModelAndBrand runs a query on database and returns a Promise.

This is the getGenerationsByModelAndBrand method code:

export const getGenerationsByModelAndBrand = (brand, model) => {
    return new Promise((resolve, reject) => {
        const sql = `DATABASE SELECT`;
        connection.query(sql, function(error, result) {
            if (error) return reject(error);
            return resolve(result);
        });
    });
};

connection comes from mysql.createConnection method from the mysql package.

I believe that the issue comes from the promise handling on the child process is like I'm missing something bu couldn't find what it is.

Edit: After researching I didn't found a solution or explanation for this issue therefore in the meantime I moved the getGenerationsByModelAndBrand to the parent script and pass the result as parameter.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!