mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 06:07:57 +00:00
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:
commit
321d9e39cf
@ -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,
|
||||
|
@ -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 = {
|
||||
|
@ -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}'`;
|
||||
|
Loading…
Reference in New Issue
Block a user