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

Abierto
#2,165 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@dveldhoen ya está trabajando en esto.

Desde el 17/11/2026.

  • #2166 de @dveldhoen — abierto
  • #2167 de @dveldhoen — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
aws, typescript
Área
cloud, devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
110
Forks
138
Merge medio
1 d 9 h
PR fusionados (30 d)
55

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws/aws-cdk-cli

Todos los issues de aws/aws-cdk-cli

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.