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); });