From 01a7f4467ffede45efc3eda3b5aec25dd0525eab Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 27 Sep 2019 21:23:33 +0200 Subject: [PATCH] Wait for end of copy until spawning tunnel Fixes the 'spawn ETXTBSY' errors as reported in https://github.com/browserstack/browserstack-runner/issues/209. The patch is inspired from https://github.com/browserstack/browserstack-local-nodejs/issues/19#issuecomment-256040404. --- lib/local.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/local.js b/lib/local.js index 15b147c..407ce7a 100644 --- a/lib/local.js +++ b/lib/local.js @@ -185,12 +185,12 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) { function(response) { response.pipe(file); - response.on('end', function() { + file.on('close', function() { fs.chmodSync(localBinary, 0700); - setTimeout(function() { - tunnelLauncher(); - }, 100); - }).on('error', function(e) { + tunnelLauncher(); + }); + + response.on('error', function(e) { logger.info('Got error while downloading binary: ' + e.message); throw new Error('Got error while downloading binary: ' + e.message); });