You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
child_process.spawn() is unreliable on Promise.all() completion #23428
$ uname -a
Linux ip-172-31-8-12 4.15.0-1021-aws #21-Ubuntu SMP Tue Aug 28 10:23:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Subsystem:
...
var spawn = require('child_process').spawn;
...
Setup:
I have a few promises that I fulfill with Promise.all().
When fulfilled, within the finally() block, I try to spawn a process and detach it.
var p1 = new Promise(function(resolve, reject) { ... });
var p2 = new Promise(function(resolve, reject) { ... });
var p3 = new Promise(function(resolve, reject) { ... });
...
Promise.all([p1, p2, p3, ...])
.then(function(vals) {
})
.catch(function(errs) {
if (errs)
console.log(errs);
})
.finally(function() {
var myScript = path.join(__dirname, '..', 'bin', 'myScript.js');
var myScriptSpawn = spawn(myScript
['-a', '-b', '-c', ...],
{
stdio : 'ignore',
detached : true,
shell : '/usr/bin/node',
env : process.env
});
myScriptSpawn.unref();
})
Problem:
Occasionally the process is spawned, occasionally the process is not spawned. This fails approximately 33% of the time. No warning, exception, or error rises when spawn fails.
Debugging:
The process myScript always works if run manually from the bash shell, outside of node. The process does not get spawned reliably when attempted within Promise.all() within node. Moving the function out of the Promise.all() fulfillment completion stage seems to work consistently.
Do all of your promises keep the event loop alive? It's possible for the process to die because there's nothing keeping the event loop alive (a promise in itself is not enough).
I'm closing this issue because of its lack of recent activity. Feel free to reopen or ask that we reopen if you think that it should still be addressed.
Activity
apapirovski commentedon Oct 18, 2018
Do all of your promises keep the event loop alive? It's possible for the process to die because there's nothing keeping the event loop alive (a promise in itself is not enough).
alexpreynolds commentedon Oct 18, 2018
I thought the node.js environment is not supposed to quit if there are items queued in the event loop.
targos commentedon Jun 14, 2020
I'm closing this issue because of its lack of recent activity. Feel free to reopen or ask that we reopen if you think that it should still be addressed.