Skip to content

Commit

Permalink
chore(cli): add image to gc docs and document race condition (#31925)
Browse files Browse the repository at this point in the history
This might be contentious given that we don't do photos in most places but afaik we do not replicate the CLI docs on the CDK docs site so it may be safe (as it renders correctly on github).

Documents garbage collection algorithm via diagram and details potentail race condition with `REVIEW_IN_PROGRESS` stacks.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Oct 29, 2024
1 parent ccab485 commit e1cd1d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,26 @@ cdk gc --unstable=gc --action=delete-tagged --rollback-buffer-days=30

This will delete assets that have been unused for >30 days, but will not tag additional assets.

Here is a diagram that shows the algorithm of garbage collection:

![Diagram of Garbage Collection algorithm](images/garbage-collection.png)

#### Theoretical Race Condition with `REVIEW_IN_PROGRESS` stacks

When gathering stack templates, we are currently ignoring `REVIEW_IN_PROGRESS` stacks as no template
is available during the time the stack is in that state. However, stacks in `REVIEW_IN_PROGRESS` have already
passed through the asset uploading step, where it either uploads new assets or ensures that the asset exists.
Therefore it is possible the assets it references are marked as isolated and garbage collected before the stack
template is available.

Our recommendation is to not deploy stacks and run garbage collection at the same time. If that is unavoidable,
setting `--created-buffer-days` will help as garbage collection will avoid deleting assets that are recently
created. Finally, if you do result in a failed deployment, the mitigation is to redeploy, as the asset upload step
will be able to reupload the missing asset.

In practice, this race condition is only for a specific edge case and unlikely to happen but please open an
issue if you think that this has happened to your stack.

### `cdk doctor`

Inspect the current command-line environment and configurations, and collect information that can be useful for
Expand Down
Binary file added packages/aws-cdk/images/garbage-collection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e1cd1d4

Please sign in to comment.