Merge pull request #904 from balena-io/fix-deltas

Fix image token authentication, and image fetch backoff in all cases
This commit is contained in:
CameronDiver 2019-02-13 16:00:15 +00:00 committed by GitHub
commit 321d9e39cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View File

@ -136,11 +136,7 @@ export class Images extends (EventEmitter as {
} catch (e) {
if (!NotFoundError(e)) {
if (!(e instanceof ImageDownloadBackoffError)) {
this.imageFetchLastFailureTime[image.name] = process.hrtime();
this.imageFetchFailures[image.name] =
this.imageFetchFailures[image.name] != null
? this.imageFetchFailures[image.name] + 1
: 1;
this.addImageFailure(image.name);
}
throw e;
}
@ -173,6 +169,7 @@ export class Images extends (EventEmitter as {
// processing
this.logger.logSystemEvent(LogTypes.deltaStillProcessingError, {});
} else {
this.addImageFailure(image.name);
this.logger.logSystemEvent(LogTypes.downloadImageError, {
image,
error: err,
@ -232,6 +229,14 @@ export class Images extends (EventEmitter as {
);
}
private addImageFailure(imageName: string, time = process.hrtime()) {
this.imageFetchLastFailureTime[imageName] = time;
this.imageFetchFailures[imageName] =
this.imageFetchFailures[imageName] != null
? this.imageFetchFailures[imageName] + 1
: 1;
}
private matchesTagOrDigest(
image: Image,
dockerImage: NormalisedDockerImage,

View File

@ -97,6 +97,7 @@ export class DockerUtils extends DockerToolbelt {
pass: deltaOpts.currentApiKey,
sendImmediately: true,
},
json: true,
};
const tokenUrl = `${tokenEndpoint}?service=${
dstInfo.registry
@ -108,7 +109,7 @@ export class DockerUtils extends DockerToolbelt {
const token = tokenResponseBody != null ? tokenResponseBody.token : null;
if (token == null) {
throw new ImageAuthenticationError();
throw new ImageAuthenticationError('Authentication error');
}
const opts: requestLib.CoreOptions = {

View File

@ -162,7 +162,8 @@ export class Logger {
if (obj && obj.error != null) {
let errorMessage = obj.error.message;
if (_.isEmpty(errorMessage)) {
errorMessage = 'Unknown cause';
errorMessage =
obj.error.name !== 'Error' ? obj.error.name : 'Unknown cause';
console.error('Warning: invalid error message', obj.error);
}
message += ` due to '${errorMessage}'`;