Skip to content

fix(cli): TCP connections are not reused - #2167

Open
dveldhoen wants to merge 1 commit into
aws:mainfrom
dveldhoen:fix/cli-keep-alive
Open

dveldhoen wants to merge 1 commit into
aws:mainfrom
dveldhoen:fix/cli-keep-alive

Conversation

@dveldhoen

Copy link
Copy Markdown

Part of #2165.

The CLI passes its ProxyAgent to the AWS SDK as httpsAgent. That replaces the SDK's default agent, which @smithy/node-http-handler creates with keepAlive: true, with one that has no keep-alive. So every SDK call opens a new TCP and TLS connection, which slows down commands that send many calls, such as cdk gc.

This passes keepAlive: true to the ProxyAgent. proxy-agent forwards its options to the http.Agent and https.Agent it uses for direct connections and to the agents it creates for proxies, so connections are reused in both cases. Node unrefs idle keep-alive sockets, so they don't keep the process alive at exit.

The new unit test sends two requests through the agent to a local server and checks that they share one connection. It fails without this change (2 connections).

Measured on a bootstrap bucket of about 24,400 objects: a local cdk gc --action=print scan of the whole bucket plus its ECR repository, with this change and an equivalent of #2166 (concurrent tag calls in cdk gc) applied as a local patch, finished in 137 seconds. With only the concurrency change, a local run ended with ECONNRESET after about 4,000 objects.

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

The CLI's ProxyAgent replaces the AWS SDK's default agent, which keeps connections alive, with one that does not, so every SDK call opened a new TLS connection. Pass keepAlive: true to the ProxyAgent.
@dveldhoen
dveldhoen requested a review from a team November 17, 2026 19:59
@github-actions github-actions Bot added the p2 label Nov 17, 2026
@rix0rrr rix0rrr changed the title fix(cli): reuse HTTPS connections for AWS SDK calls fix(cli): TCP connections are not reused Nov 30, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.52%. Comparing base (9f41f76) to head (307c7eb).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2167      +/-   ##
==========================================
- Coverage   92.55%   92.52%   -0.03%     
==========================================
  Files          81       81              
  Lines       13224    13228       +4     
  Branches     1915     1913       -2     
==========================================
  Hits        12239    12239              
- Misses        947      951       +4     
  Partials       38       38              
Flag Coverage Δ
suite.unit 92.52% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch is waiting to be deployed

1 inactive and 1 waiting deployments
integ-approval — 307c7ebb Waiting Nov 17, 2026 by dveldhoen via prepare #7755
automation — 307c7ebb Deployed Nov 17, 2026 by dveldhoen via Set AutoQueue on PR #2167 #4020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants