fix: prevent AbortSignal listener memory leak#1811
Merged
Conversation
- Add abort listener cleanup in Query.close() to prevent memory leak - Add abort listener cleanup in ControlDispatcher.shutdown() - Remove AbortController recreation in Session.handleInterrupt() This fixes the MaxListenersExceededWarning that occurred when: - Creating 11+ Query instances in SDK/non-interactive mode - Multiple user interrupts (Ctrl+C) in interactive mode - Intensive control request scenarios
Contributor
📋 Review SummaryThis PR addresses a memory leak caused by AbortSignal event listeners not being properly removed, which triggered 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
✅ Highlights
|
This was referenced Feb 12, 2026
Closed
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
Mingholy
approved these changes
Feb 12, 2026
Mingholy
left a comment
Collaborator
There was a problem hiding this comment.
Good fix. Let's merge this ASAP.
xaelistic
pushed a commit
to xaelistic/qwen-code
that referenced
this pull request
Jun 7, 2026
…leak fix: prevent AbortSignal listener memory leak
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.
TLDR
Fixes memory leak caused by AbortSignal event listeners not being properly removed, which triggered
MaxListenersExceededWarningafter 11+ operations.Dive Deeper
Root Cause
Three locations were adding
abortevent listeners to AbortSignal but never removing them:close()didn't remove itshutdown()didn't remove ithandleInterrupt()created new AbortController without cleaning up old listenersChanges Made
removeEventListener()inclose()removeEventListener()inshutdown()Impact
Reviewer Test Plan
npm run build(already tested ✅)integration-tests/sdk-typescript/abort-and-lifecycle.test.tsTesting Matrix
npm run build- compilation successfulabort-and-lifecycle.test.tscover abort scenariosLinked issues / bugs
#1787
#1810