Skip to content

Commit

Permalink
fix(downloader): increase timeouts and unlink sync on download errors (
Browse files Browse the repository at this point in the history
…#75)

closes #62 and #63
  • Loading branch information
cnishina committed Aug 8, 2016
1 parent fa20ca8 commit 236a8ec
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/files/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 236a8ec

Please sign in to comment.