Skip to content
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

ecr: Garbage collection for ECR prints runs indefinitely #32742

Closed
1 task
BwL1289 opened this issue Jan 5, 2025 · 13 comments
Closed
1 task

ecr: Garbage collection for ECR prints runs indefinitely #32742

BwL1289 opened this issue Jan 5, 2025 · 13 comments
Assignees
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@BwL1289
Copy link

BwL1289 commented Jan 5, 2025

Describe the bug

Seeing unexpected behavior, specifically in ECR.

In one account I see the following:

...
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[10:33:17] [sdk info] ECR.PutImage({"repositoryName":"cdk-hnb659fds-container-assets-<redacted>-<redacted>","imageDigest":"sha256:<redacted>","imageManifest":"{\n   \"schemaVersion\": 2,\n   \"mediaType\": \"<redacted>\",\n   \"config\": {\n      \"mediaType\": \"<redacted>\",\n      \"size\": 5901,\n      \"digest\": \"sha256:<redacted>\"\n   },\n   \"layers\": [\n      {\n         \"mediaType\": \"<redacted>\",\n         \"size\": 51425992,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 123664308,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 12743115,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 91031203,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 213512017,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 9206109,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 11062104,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 45374,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 29905,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 1361,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 346,\n         \"digest\": \"sha256:<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 220,\n         \"digest\": \"sha256:<redacted>\"\n      }\n   ]\n}","imageTag":"443-aws-cdk.isolated-<redacted>"}) -> OK
[10:33:17] Tagged 444 assets
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[10:33:17] Reading cached notices from /Users/benjaminleff/.cdk/cache/notices.json
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[57.46%] 1468 files scanned: 1362 assets (2105.36 GiB) tagged, 0 assets (0.00 GiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.
[100.00%] 4762 files scanned: 0 assets (0.00 MiB) tagged, 0 assets (0.00 MiB) deleted.

This continues seemingly indefinitely. It's also strange that the verbose flag stops working after some period of time.

In another account I see the following:

...
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[09:46:49] [sdk info] ECR.PutImage({"repositoryName":"cdk-hnb659fds-container-assets-<redacted>-<redacted>","imageDigest":"sha256:<redacted>
<redacted>","imageManifest":"{\n   \"schemaVersion\": 2,\n   \"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",\n   \"config\": {\n      \"mediaType\": \"application/vnd.docker.container.image.v1+json\",\n      \"size\": 9791,\n      \"digest\": \"sha256:<redacted>
<redacted>\"\n   },\n   \"layers\": [\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 51425992,\n         \"digest\": \"sha256:<redacted>
<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 6857210421,\n         \"digest\": \"sha256:<redacted>
<redacted>\"\n      },\n      {\n         \"mediaType\": \"application/vnd.docker.image.rootfs.diff.tar.gzip\",\n         \"size\": 236,\n         \"digest\": \"sha256:<redacted>
<redacted>\"\n      }\n   ]\n}","imageTag":"186-aws-cdk.isolated-<redacted>"}) -> OK
[09:46:51] Tagged 187 assets
[21.78%] 294 files scanned: 187 assets (405.60 GiB) tagged, 0 assets (0.00 GiB) deleted.
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[09:46:51] Reading cached notices from /Users/benjaminleff/.cdk/cache/notices.json
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted.
[99.73%] 1839 files scanned: 2 assets (0.34 MiB) tagged, 0 assets (0.00 MiB) deleted
...

This also continues seemingly indefinitely. Same with verbose flag behavior not working as expected after some period of time.

I've left it running for 6 hours and still the same.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

Delete all unused ecr and s3 cdk assets.

Current Behavior

Ecr and s3 assets that are unused are not being deleted and runs indefinitely.

Reproduction Steps

Run cdk gc --unstable='gc' --type='all' -vvvv --rollback-buffer-days=1

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.174.0

Framework Version

No response

Node.js Version

22.12.0

OS

MacOS

Language

Python

Language Version

No response

Other information

No response

@BwL1289 BwL1289 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 5, 2025
@github-actions github-actions bot added the @aws-cdk/assets Related to the @aws-cdk/assets package label Jan 5, 2025
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 6, 2025
@khushail khushail self-assigned this Jan 6, 2025
@khushail
Copy link
Contributor

khushail commented Jan 6, 2025

Hi @BwL1289 , thanks for reaching out. Looks like a similar issue with garbage collector was reported few days ago and fix was also put in place last week- #32679
Just curious have you recently tried this with the latest version and still facing the issue ?

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jan 6, 2025
@BwL1289
Copy link
Author

BwL1289 commented Jan 6, 2025

Hi @khushail. I am using v2.174.0 which is the latest version.

@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 6, 2025
@khushail
Copy link
Contributor

khushail commented Jan 6, 2025

@BwL1289 , thanks for the confirmation. I tried to repro the scenario in my account with the latest version and here is what I am getting -

Screenshot 2025-01-06 at 11 09 00 AM

Images are being tagged but not deleted. Trying to reproduce it in other region.

@BwL1289
Copy link
Author

BwL1289 commented Jan 6, 2025

@khushail I am seeing the same behavior, in addition to what I described originally.

@pahud pahud changed the title (aws-cdk/lib/api/garbage-collection): Garbage collection for ECR prints runs indefinitely ecr: Garbage collection for ECR prints runs indefinitely Jan 6, 2025
@kaizencc
Copy link
Contributor

kaizencc commented Jan 6, 2025

This is strange @BwL1289, sorry that you are experiencing this. If this is a nextToken issue as we thought before, I believe a repro with 1000+ images in the ecr repo would help. However, before I get to that tomorrow, I just want to make sure -- you are on CDK CLI version 2.174.0, not just aws-cdk-lib 2.174.0 right?

@khushail khushail removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Jan 6, 2025
@khushail khushail removed their assignment Jan 6, 2025
@khushail khushail added the effort/small Small work item – less than a day of effort label Jan 6, 2025
@BwL1289
Copy link
Author

BwL1289 commented Jan 6, 2025

@kaizencc all good. Appreciate the support. Yes, on CDK CLI version 2.174.0

Screenshot 2025-01-06 at 2 58 32 PM

@kaizencc kaizencc self-assigned this Jan 6, 2025
@BwL1289
Copy link
Author

BwL1289 commented Jan 7, 2025

@kaizencc also just to clarify, I don't believe it's only a nextToken issue (I experienced that before the latest fix). In the previous version in the verbose output I could see the same image ids being iterated over.

Now I'm seeing images also get tagged but not deleted.

What's also interesting is the verbose output stops after a period of time running.

@BwL1289
Copy link
Author

BwL1289 commented Jan 8, 2025

@kaizencc were you able to reproduce?

@BwL1289
Copy link
Author

BwL1289 commented Jan 20, 2025

@sakurai-ryo out of curiosity does #32985 resolve this? Thank you.

@sakurai-ryo
Copy link
Contributor

Hi @BwL1289
It's probably resolved, so could you try it out once it's merged?

@BwL1289
Copy link
Author

BwL1289 commented Jan 22, 2025

Thanks @sakurai-ryo. Will do.

mergify bot pushed a commit that referenced this issue Feb 10, 2025
…ction (#32985)

### Issue # (if applicable)

Related to #32742 

### Reason for this change
In the `garbageCollectS3` and `garbageCollectEcr` functions, a new `setInterval` is created in the `ProgressPrinter` class each time the for-await loop runs.
As a result, the old `setInterval` can no longer be referenced via `this.setInterval`, and because it cannot be cleared, the messages continue to be displayed.

https://github.com/aws/aws-cdk/blob/899965d6147829b8f8ac52ac8c1350de50d7b6d0/packages/aws-cdk/lib/api/garbage-collection/progress-printer.ts#L44

This behavior is the same as what occurs in the simple sample code below.
```ts
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

class Printer {
  private setInterval?: ReturnType<typeof setTimeout>

  public start() {
    this.setInterval = setInterval(() => {
      console.log("Hello, world!")
    }, 1000)
  }

  public stop() {
    clearInterval(this.setInterval)
  }
}

;(async () => {
  const printer = new Printer()

  // print one message per second for 5 seconds
  printer.start()
  await sleep(5000)

  // print tow messages per second for 5 seconds
  printer.start()
  await sleep(5000)

  // clear the newer setInterval
  // the older one will still be running
  printer.stop()
})()
```

### Description of changes
It didn't seem necessary to initialize `setInterval` each time the for-await loop runs, so I modified the code to call `.start()` before the loop begins.

### Describe any new or updated permissions being added
Nothing.

### Description of how you validated changes

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@BwL1289
Copy link
Author

BwL1289 commented Feb 18, 2025

Confirm the newest fix works as expected.

@BwL1289 BwL1289 closed this as completed Feb 18, 2025
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

4 participants