(garbage-collection): cdk gc takes hours on a large bootstrap bucket

Đang mở
#2,165 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@dveldhoen đang làm issue này rồi.

Từ ngày 17/11/2026.

  • #2166 của @dveldhoen — đang mở
  • #2167 của @dveldhoen — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
aws, typescript
Lĩnh vực
cloud, devtools

Hướng nghiên cứu

Read packages/@aws-cdk/toolkit-lib/lib/api/garbage-collection/garbage-collector.ts around parallelReadAllTags, parallelTagS3 and parallelUntagS3, then inspect packages/aws-cdk/lib/cli/proxy-agent.ts around the ProxyAgent configuration. Check how the existing parallelPromises helper and SDK HTTP agent options are used. Done means S3 tag calls run concurrently up to the limiter's 50-call limit and reuse connections; the issue reports a 24,400-object scan completing in minutes with both fixes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

cdk gc reads and writes S3 object tags one call at a time, and the CLI opens a new TLS connection for every call. On a bootstrap bucket with about 24,000 objects, a run takes hours. In CI it got through about 2,000 objects in 30 minutes before the job timed out, and because every run starts again at the beginning of the bucket, it never caught up.

There are two causes:

  1. parallelReadAllTags, parallelTagS3 and parallelUntagS3 await each call inside their loop, so the pLimit(50) limiter never has more than one call in flight:
    https://github.com/aws/aws-cdk-cli/blob/9f41f76683c1dfcf80b356a8c1e77094da97ef54/packages/%40aws-cdk/toolkit-lib/lib/api/garbage-collection/garbage-collector.ts#L423-L429
  2. The CLI passes its ProxyAgent to the SDK as httpsAgent. That replaces the SDK's default agent, which @smithy/node-http-handler creates with keepAlive: true and maxSockets: 50, with one that has no keep-alive, so every SDK call opens a new connection:
    https://github.com/aws/aws-cdk-cli/blob/9f41f76683c1dfcf80b356a8c1e77094da97ef54/packages/aws-cdk/lib/cli/proxy-agent.ts#L137-L143
Regression Issue
  • Select this option if this issue appears to be a regression.
Last Known Working CDK Version

No response

Expected Behavior

cdk gc runs up to 50 tag calls at a time, as the limiter intends, over reused connections, and finishes a bucket of this size in minutes.

Current Behavior

Tag calls run one at a time, each over a new TLS connection. From a GitHub-hosted runner to a bucket in another region, a run processed about 1 object per second and hit the 30-minute job timeout every time.

Reproduction Steps
  1. Use an environment whose bootstrap bucket holds many objects, for example 20,000 or more, which accumulate on an account that deploys several times a day.
  2. Run cdk gc aws://<account>/<region> --unstable=gc --type=s3 --action=print.
  3. The scan progresses at roughly one object per network round trip plus a TLS handshake.
Possible Solution

Run the S3 tag calls through the existing parallelPromises helper with the same limit, and pass keepAlive: true to the CLI's ProxyAgent. I'll open a PR for each.

With both fixes applied as a local patch (Promise.all through the existing limiter, plus keep-alive), a local cdk gc --unstable=gc --action=print scan (no tagging or deleting) of the whole bucket (about 24,400 objects) and its ECR repository finished in 137 seconds. With only the first change, about 4,000 objects took 6 minutes, and the run then ended with S3GarbageCollectionFailed: TimeoutError: read ECONNRESET.

Additional Information/Context

The ECR loops (parallelTagEcr, parallelUntagEcr) follow the same pattern. I left them out of the PRs to keep to the S3 path I measured. ECR's API rate quotas are lower than S3's, so running those calls concurrently deserves its own look.

CDK CLI Version

2.1148.1 (build fcf5e34)

Framework Version

2.277.0

Node.js Version

24.22.2

OS

Ubuntu 24.04 (GitHub Actions) and macOS

Language

TypeScript

Language Version

No response

Other information

No response

Ngôn ngữ chính
TypeScript
Star
110
Fork
138
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
55

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws/aws-cdk-cli

Tất cả issue của aws/aws-cdk-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.