From dd7f7428d6291121929853e95cc9945eac60b907 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Fri, 5 Aug 2016 11:04:18 -0700 Subject: [PATCH] fix(downloader): increase timeouts and unlink sync on download errors closes #62 and #63 --- lib/files/downloader.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/files/downloader.ts b/lib/files/downloader.ts index 91ee8f06..73b69661 100644 --- a/lib/files/downloader.ts +++ b/lib/files/downloader.ts @@ -127,22 +127,32 @@ export class Downloader { url: fileUrl, strictSSL: !opt_ignoreSSL, rejectUnauthorized: !opt_ignoreSSL, - proxy: Downloader.resolveProxy_(fileUrl, opt_proxy) + proxy: Downloader.resolveProxy_(fileUrl, opt_proxy), + // default Linux can be anywhere from 20-120 seconds + // increasing this arbitrarily to 4 minutes + timeout: 240000 }; request(options) .on('response', (response) => { if (response.statusCode !== 200) { - fs.unlink(filePath); + fs.unlinkSync(filePath); logger.error('Error: Got code ' + response.statusCode + ' from ' + fileUrl); } contentLength = response.headers['content-length']; }) .on('error', (error) => { - logger.error('Error: Got error ' + error + ' from ' + fileUrl); - fs.unlink(filePath); + if (error.code === 'ETIMEDOUT') { + logger.error('Connection timeout downloading: ' + fileUrl); + logger.error('Default timeout is 4 minutes.'); + + } else if (error.connect){ + logger.error('Could not connect to the server to download: ' + fileUrl); + } + logger.error(error); + fs.unlinkSync(filePath); }) .pipe(file); @@ -156,7 +166,7 @@ export class Downloader { logger.error( 'Error: corrupt download for ' + fileName + '. Please re-run webdriver-manager update'); - fs.unlink(filePath); + fs.unlinkSync(filePath); return; } if (callback) {