From ecf7e4206c47627a28896abf083b9362c04fe619 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Fri, 27 Oct 2017 18:25:43 -0700 Subject: [PATCH] Avoid fetching an image when it might be available or when starting an app because it might not be necessary This change removes the behavior where we would try to fetch an app image when starting the app. This might cause an unintended download of an app that is not really needed anymore because we're starting the app on boot and an update cycle would make this image unnecessary. So now we try to inspect the image, and if this fails we will throw an error, causing the app to be soft-deleted and the next update cycle to properly trigger a download of whatever image we need from the target state. We also improve the error catching when fetching an image, to specifically catch an "image not found" error before trying to download - otherwise, any other random error will cause us to try to download the image again, which will not be a noop if we're using deltas. If there's any other error, the correct behavior is to throw and retry later. Change-Type: patch Signed-off-by: Pablo Carranza Velez --- src/application.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/application.coffee b/src/application.coffee index 83d29c2b..24f587c0 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -210,7 +210,7 @@ fetch = (app, { deltaSource, setDeviceUpdateState = true } = {}) -> device.updateState(download_progress: progress.percentage) docker.getImage(app.imageId).inspect() - .catch (error) -> + .catch ImageNotFoundError, -> device.updateState(status: 'Downloading', download_progress: 0) Promise.try -> @@ -286,7 +286,8 @@ application.start = start = (app) -> # If there is no existing container then create one instead. containerPromise.catch -> - fetch(app) + # If the image is not available, we'll let the update cycle fix it + docker.getImage(app.imageId).inspect() .then (imageInfo) -> logSystemEvent(logTypes.installApp, app) device.updateState(status: 'Installing')