$ 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
...
var spawn = require('child_process').spawn;
...
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();
})
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.
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.
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.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.
The process
myScriptalways works if run manually from thebashshell, outside ofnode. The process does not get spawned reliably when attempted withinPromise.all()withinnode. Moving the function out of thePromise.all()fulfillment completion stage seems to work consistently.