fix(aws-cdk): remove SIGINT listener leak in TelemetrySession - #1863
Open
Adityaj0 wants to merge 1 commit into
Open
fix(aws-cdk): remove SIGINT listener leak in TelemetrySession#1863Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
fixes aws#1862 TelemetrySession.begin() registered a listener on the process-global SIGINT event on every call, and nothing ever removed it -- not in begin(), not in end(), not anywhere else. Each closure retains the full TelemetrySession (ioHost, telemetry client, sanitized session info), so this is a real leak, not just a stray function reference: every begin() call in a long-running process (e.g. calling exec() more than once without exiting, as this repo's own cli.test.ts / cli-commands.test.ts / deploy-options.test.ts etc. do) permanently pins another retained object graph, and past 10 accumulated listeners Node prints MaxListenersExceededWarning. Store the listener reference on the instance and remove it in end(), which is already called on both the normal-completion path (cli.ts's .finally()) and the SIGINT path itself. Added a regression test that asserts process.listenerCount('SIGINT') does not grow across 20 begin()/end() cycles. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adityaj0
requested a deployment
to
integ-approval
August 20, 2026 10:14 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
August 20, 2026 10:14
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1863 +/- ##
==========================================
+ Coverage 90.96% 90.98% +0.02%
==========================================
Files 80 80
Lines 12257 12269 +12
Branches 1761 1764 +3
==========================================
+ Hits 11149 11163 +14
+ Misses 1071 1069 -2
Partials 37 37
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #1862
Reason for this change
TelemetrySession.begin()registers a listener on the process-globalSIGINTevent every time it's called:Nothing ever removes it. Each closure retains the full
TelemetrySession--ioHost, the telemetryclient, sanitized session info -- so everybegin()call in a process that runs more than once without exiting (e.g. driving the CLI'sexec()programmatically, or this repo's own in-process test suite:cli.test.ts,cli-commands.test.ts,deploy-options.test.ts,import-options.test.ts,diff-options.test.ts, ...) permanently leaks another retained object graph. Past 10 accumulated listeners you'd see Node'sMaxListenersExceededWarning. It's also a latent correctness bug: if SIGINT ever fires with multiple accumulated listeners, all of them race toend()andprocess.exit().Description of changes
TelemetrySessionnow stores the SIGINT listener it registers inbegin()on a private field.end()(already called on both the normal-completion path incli.ts's.finally()and the SIGINT path itself) now removes that listener before doing anything else, so a session's listener is cleaned up exactly once regardless of which path ended it.Testing
Added two tests to
test/cli/telemetry/session.test.ts:begin()registers exactly one SIGINT listener, andend()removes it — asserts the delta is exactly -1.exec()calls in one long-running host process) assertsprocess.listenerCount('SIGINT')returns to baseline every time, i.e. no net growth.Full
test/cli/telemetry/session.test.ts(34 tests) andtest/cli/io-host/(91 tests) suites pass. (Note: several unrelatedtest/cli/*suites currently fail to run locally on a fresh checkout due to a pre-existing missing-build-artifact issue --@aws-cdk/cdk-explorernot being built andbuild-info.jsonnot being generated -- unrelated to this change; verified the failures are all in that category and none mention telemetry/session.)Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license