Skip to content

Some callbacks to child_process.exec are never called #26

@joshterrell805

Description

@joshterrell805

If execSync.exec is used before node's child_process.exec, the exec callback to child_process.exec is never called.

This only happens when multiple calls to execSync and child_process.exec are invoked one after the other.

Example script to demonstrate the issue:

 var exec = require('child_process').exec,
     execSync = require('execSync');

 var executions = 5;

 var execFunctions = [];

 for (var i = 0; i < executions; ++i) {
    addExecFunction(i);
 }

 var completedExecutions = 0;
 execFunctions.forEach(function(execFunction) {
    execFunction(function(err, val) {
       if (++completedExecutions == executions) {
          console.log('all complete!');
       }
    });
 });

 function addExecFunction(i) {
    execFunctions.push(function(callback) {
       console.log(i + ' start');
       var pwd = execSync.exec('cd && pwd').stdout.replace('\n', '');
       //var pwd = '~';
       var command = 'ls -l ' + pwd;
       //console.log(command);
       exec(command, function onProcessTermination(err, stdout, stderr) {
          console.log(i + ' complete');
          callback(null, i);
       });
    });
 }

output:

$ node testExec.js
0 start
1 start
2 start
3 start
4 start
3 complete
4 complete

When commenting out var pwd = execSync.exec(...);, and uncommenting var pwd = '~'; the script works fine.

PS: I'm running this on a linux box.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions