Skip to content

Commit

Permalink
Force remove container if updateMetadata fails
Browse files Browse the repository at this point in the history
The `updateMetadata` step renames the container to match the target
release when the service doesn't change between releases. We have seen
this step fail because of an engine bug that seems to relate to the
engine keeping stale references after container restarts. The only way
around this issue is to remove the old container and create it again.
This implements that workaround during the updateMetadata step to deal
with that issue.

Change-type: minor
Relates-to: balena-os/balena-engine#261
  • Loading branch information
pipex committed Nov 15, 2023
1 parent dd5f9c8 commit c1b9b05
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/compose/service-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,20 @@ export async function updateMetadata(service: Service, target: Service) {
);
}

await docker.getContainer(svc.containerId).rename({
name: `${service.serviceName}_${target.imageId}_${target.releaseId}_${target.commit}`,
});
try {
await docker.getContainer(svc.containerId).rename({
name: `${service.serviceName}_${target.imageId}_${target.releaseId}_${target.commit}`,
});
} catch (e) {
if (isNotFoundError(e)) {
log.warn(
'Got 404 error while updating container metadata. Will attempt to recreate the container instead',
e,
);
return await docker.getContainer(svc.containerId).remove({ force: true });
}
throw e;
}
}

export async function handover(current: Service, target: Service) {
Expand Down

0 comments on commit c1b9b05

Please sign in to comment.