Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

Commit

Permalink
Bug 1302596: Retry image download when it fails
Browse files Browse the repository at this point in the history
We already have retries for when the download fails, but not when the
downloaded image is corrupted.

We add a retry for the general `ensureImage()` function, for edge cases
like above.

As we are not retrying because of possible network temporary outage, we
configure the waiting time to be a small value.
  • Loading branch information
walac committed Sep 3, 2019
1 parent fa5a222 commit 27ef182
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lib/docker/artifact_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class ArtifactImage {

return true;
} catch(e) {
this.stream.write(fmtLog(`Downloaded image is corrupted: ${e.message}`));
delete this.knownHashes[`${this.taskId}-${this.artifactPath}`];
return false;
}
Expand Down
20 changes: 16 additions & 4 deletions src/lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const uploadToS3 = require('./upload_to_s3');
const _ = require('lodash');
const EventEmitter = require('events');
const libUrls = require('taskcluster-lib-urls');
const promiseTry = require('promise-retry');

let debug = new Debug('runTask');

Expand Down Expand Up @@ -869,10 +870,21 @@ class Task extends EventEmitter {
let imageId;
try {
let im = this.runtime.imageManager;
imageId = await im.ensureImage(this.task.payload.image,
this.stream,
this,
this.task.scopes);

imageId = await promiseRetry(retry => {
return im.ensureImage(
this.task.payload.image,
this.stream,
this,
this.task.scopes).catch(retry);
}, {
maxTimeout: 1000,
minTimeout: 10,
factor: 1.2,
randomize: true,
retries: 3,
});

this.imageHash = imageId;
this.runtime.gc.markImage(imageId);
} catch (e) {
Expand Down

0 comments on commit 27ef182

Please sign in to comment.