Fix for stdout race condition in stf doctor

Sometimes the process exits before the data is read from stdout. The result is that the `call` method exits before it has it's output.

Example bug: https://github.com/openstf/stf/issues/1091
This commit is contained in:
Rick van Hattem
2019-11-06 12:26:31 +01:00
committed by GitHub
parent d4efda70d7
commit d371e733d2

View File

@@ -30,16 +30,13 @@ module.exports.handler = function() {
var proc = cp.spawn(command, args, options)
var stdout = []
proc.stdout.on('readable', function() {
var chunk
while ((chunk = proc.stdout.read())) {
stdout.push(chunk)
}
proc.stdout.on('data', function(data) {
stdout.push(data)
})
proc.on('error', reject)
proc.on('exit', function(code, signal) {
proc.on('close', function(code, signal) {
if (signal) {
reject(new CheckError('Exited with signal %s', signal))
}