-
Notifications
You must be signed in to change notification settings - Fork 50
feat: add retry to remove docker image #1739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import com.aws.greengrass.componentmanager.models.ComponentIdentifier; | ||
import com.aws.greengrass.componentmanager.models.ComponentRecipe; | ||
import com.aws.greengrass.componentmanager.plugins.docker.exceptions.ConnectionException; | ||
import com.aws.greengrass.componentmanager.plugins.docker.exceptions.DockerImageDeleteException; | ||
import com.aws.greengrass.componentmanager.plugins.docker.exceptions.DockerLoginException; | ||
import com.aws.greengrass.componentmanager.plugins.docker.exceptions.DockerServiceUnavailableException; | ||
import com.aws.greengrass.dependency.Context; | ||
|
@@ -61,9 +62,16 @@ public class DockerImageDownloader extends ArtifactDownloader { | |
private RetryUtils.RetryConfig finiteAttemptsRetryConfig = | ||
RetryUtils.RetryConfig.builder().initialRetryInterval(Duration.ofSeconds(10L)) | ||
.maxRetryInterval(Duration.ofMinutes(32L)).maxAttempt(30).retryableExceptions( | ||
Arrays.asList(DockerServiceUnavailableException.class, DockerLoginException.class, | ||
Arrays.asList(DockerServiceUnavailableException.class, DockerLoginException.class, | ||
SdkClientException.class, ServerException.class)).build(); | ||
|
||
@Setter(AccessLevel.PACKAGE) | ||
private RetryUtils.RetryConfig finiteDeleteAttemptsRetryConfig = | ||
RetryUtils.RetryConfig.builder().initialRetryInterval(Duration.ofSeconds(10L)) | ||
.maxRetryInterval(Duration.ofMinutes(2L)).maxAttempt(5).retryableExceptions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. These configs are flagged under GS-Tech Static config campaign and is considered to be a violation. Please migrate these configs |
||
Arrays.asList(DockerServiceUnavailableException.class, DockerLoginException.class, | ||
DockerImageDeleteException.class)).build(); | ||
|
||
/** | ||
* Constructor. | ||
* | ||
|
@@ -310,15 +318,20 @@ private <T> T runWithConnectionErrorCheck(CrashableSupplier<T, Exception> task) | |
*/ | ||
@Override | ||
public void cleanup() throws IOException { | ||
// this docker image not only used by itself | ||
try { | ||
if (!ifImageUsedByOther(componentStore)) { | ||
Image image = DockerImageArtifactParser | ||
.getImage(ComponentArtifact.builder().artifactUri(artifact.getArtifactUri()).build()); | ||
dockerClient.deleteImage(image); | ||
RetryUtils.runWithRetry(finiteDeleteAttemptsRetryConfig, () -> { | ||
|
||
Image image = DockerImageArtifactParser | ||
.getImage(ComponentArtifact.builder().artifactUri(artifact.getArtifactUri()).build()); | ||
dockerClient.deleteImage(image); | ||
return null; | ||
}, "docker-image-cleanup", logger); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extremely nit: I have a similar complaint with the formatting here |
||
} catch (PackageLoadingException | InvalidArtifactUriException e) { | ||
} catch (PackageLoadingException | InvalidArtifactUriException | InterruptedException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. Problem: InterruptedException is ignored. This can delay thread shutdown and clear the thread’s interrupt status. Only code that implements a thread’s interruption policy can swallow an interruption request. Fix: Rethrow the InterruptedException or reinterrupt the current thread using Thread.currentThread().interrupt() so that higher-level interrupt handlers can function correctly. Remember: Do this only for InterruptedException. Doing this for other types of exceptions may give rise to subtle bugs. Learn more about interrupts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 I think the behavior and the warning message thrown for an Interrupted Exception should be different. I also think current thread needs to be interrupted as recommended in this comment. Also, in my head, the error handling should look a bit like this
Lastly, please log the component artifact which we were unable to delete. |
||
throw new IOException(e); | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. It appears that your code handles a broad swath of exceptions in the catch block, potentially trapping dissimilar issues or problems that should not be dealt with at this point in the program. |
||
throw new IOException("Failed to cleanup docker image after retries", e); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extremely nit: i dont think this is formatted as expected. Can you take a look?