From d371e733d2bd63c8800f7f4e484656984fd0e057 Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Wed, 6 Nov 2019 12:26:31 +0100 Subject: [PATCH] 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 --- lib/cli/doctor/index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/cli/doctor/index.js b/lib/cli/doctor/index.js index 249e3da7..7e8540a7 100644 --- a/lib/cli/doctor/index.js +++ b/lib/cli/doctor/index.js @@ -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)) }