Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process exec callback not called (sometimes) #25405

Closed
torakiki opened this issue Sep 10, 2020 · 3 comments · Fixed by #25869
Closed

child_process exec callback not called (sometimes) #25405

torakiki opened this issue Sep 10, 2020 · 3 comments · Fixed by #25869

Comments

@torakiki
Copy link

Issue Details

  • Electron Version:
    • 9.2.1
    • 10.1.1
  • Operating System:
    • Windows 64 and 32
  • Last Known Working Electron version:
    • 8.5.1

With version 9.2.1 and 10.1.1 it happens that sometimes the child_process.exec callback is never called. It seems fine with version 8.5.1 (still testing)

We have this code that sometimes doesn't call the callback, meaning it never print 'finished' on Windows 32 and 64bits.

const exec = require('child_process').exec;

const execPromise = (cmd, execOpts) => {
    return new Promise(function(resolve, reject) {
	    console.log('start')
        exec(cmd, execOpts, (error, stdout, stderr) => {
		console.log('finished')
            if (error) {
                error.stdout = stdout;
                error.stderr = stderr
                reject(error);
                return;
            }
            resolve({stdout: stdout, stderr: stderr});
        });
    });
}

The command we exec is a Java command and we can see from the task manager the shell process is created and also the Java process, most of the times everything works as expected but sometimes we can see the processes disappearing from the task manager and the callback is not called (finished is never printed in the console), causing a major issue with our application because we are not able to notify the user that the task has finished.

  • Again, we see the processes disappearing from the task manager and the callback doesn't print anything
  • It seems to be Windows specific, on Linux it doesn't happen.
  • It's shouldn't be related to the cmd, it's always the same command with different args and, anyway, I'd expect the callback with an error if there's something wrong with cmd.
  • It usually happens every 4 or 5 executions
  • We downgraded to version 8.5.1 and it seems there issue is not there, we can run 20 tasks one after the other and we don't experience any issue
  • Same thing happens with util.promisify of the require('child_process').exec;

Any idea?

@W4545
Copy link

W4545 commented Oct 6, 2020

Can confirm I'm experiencing the same issue. 10% of the time the callback is not called.

@hatton
Copy link

hatton commented Oct 12, 2020

Same thing here, on Windows. I haven't tried on mac or linux yet. It can be very difficult for me to reproduce. Fortunately, the next time I do a child_process.exec(), the pending one will always returns immediately. So for the moment I rely on this monstrosity:

  let didCallback = false;
  window.setTimeout(() => {
    if (!didCallback) {
      child_process.exec("call"); // does nothing on Windows, but causes a previously recalcitrant callback to fire
    }
  }, 2000);

@codebytere
Copy link
Member

Should be fixed by #25869

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants