aws / aws/aws-cdk-cli

(cli) CDK CLI hangs indefinitely after command completion in CI environments (GitLab/Kubernetes) - v2.1034.0+

Open
#1,217 13 comments 0 reactions 1 assignee Claimed by @sai-ray View on GitHub
bug p1
Dominant language
TypeScript
Stars
105
Forks
122
Avg merge
1d 17h
Merged PRs (30d)
71

Description

### Describe the bug

After upgrading AWS CDK CLI from v2.1033.0 to v2.1034.0+, the CLI process hangs indefinitely after cdk deploy or cdk diff commands complete successfully in GitLab CI (Kubernetes executor). The command output shows completion (e.g., "✨ Number of stacks with differences: 0") but the process never exits, requiring manual cancellation.
This issue does not occur when running the same commands locally on macOS - only in CI environments.

### Investigation findings:
Telemetry connects despite being disabled: Setting CDK_DISABLE_CLI_TELEMETRY=1 shows disableTelemetry: 1 in verbose output, but logs still show Endpoint Telemetry connected and Telemetry Sent Successfully.

--no-telemetry flag partially helps: Using --no-telemetry correctly shows telemetry: false and Endpoint Telemetry NOT connected, but the process still hangs.

Another likely root cause: AWS SDK v3 HTTP connections (to STS, CloudFormation, S3, SSM) are not being properly closed, keeping the Node.js event loop alive. In CI environments without a TTY, these connections don't trigger cleanup.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Library Version

2.1033.0

### Expected Behavior

The CDK CLI process should exit cleanly (exit code 0) after the command completes, just as it does in local terminal environments.

### Current Behavior

1. Command runs and completes successfully
2. Output shows completion message (e.g., ✨ Command time: 69.51s)
3. With CDK_DISABLE_CLI_TELEMETRY=1: Telemetry still connects and sends data, then process hangs
4. With --no-telemetry: Telemetry doesn't connect, but process still hangs
5. Process must be manually killed/canceled after several minutes

### Reproduction Steps

1. Create a GitLab CI pipeline using Kubernetes executor
2. Run any CDK command (cdk diff, cdk deploy, cdk synth)
3. Observe the command completes successfully with output
4. Process hangs indefinitely instead of exiting

```
# .gitlab-ci.yml
cdk-diff:
image: node:22
script:
- npm install -g aws-cdk
- export CDK_DISABLE_CLI_TELEMETRY=1
- cdk diff --ci -c env=development -v -v
```

### Possible Solution

_No response_

### Additional Information/Context

Relevant log snippets:

# With env var only (telemetry still connects despite disable flag)
disableTelemetry: 1,
telemetry: undefined,
[15:01:18] Endpoint Telemetry connected # ← Should NOT connect
[15:02:28] Telemetry Sent Successfully # ← Should NOT send
# Process hangs here

# With --no-telemetry flag (telemetry disabled, but still hangs)
telemetry: false,
[16:56:23] Endpoint Telemetry NOT connected # ✓ Correct
[16:58:02] ✨ Number of stacks with differences: 0
# Process hangs here (no "Command time" output)

### AWS CDK Library version (aws-cdk-lib)

2.1.034.0+

### AWS CDK CLI version

N/A

### Node.js Version

22.22.0

### OS

Ubuntu - Kuberneter Executor Container

### Language

Java

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.