fix(hooks): clean up abort listener in error handler#2841
Merged
DennisYu07 merged 1 commit intoQwenLM:mainfrom Apr 3, 2026
Merged
fix(hooks): clean up abort listener in error handler#2841DennisYu07 merged 1 commit intoQwenLM:mainfrom
DennisYu07 merged 1 commit intoQwenLM:mainfrom
Conversation
The error handler in hookRunner cleared the timeout but did not remove the abort signal listener, unlike the close handler. When spawn fails (e.g. executable not found), only the error event fires — the close event is not guaranteed — so the abort listener leaked on the signal.
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.
Fix abort listener leak in hook runner error handler.
TLDR
Adds missing
signal.removeEventListener('abort', abortHandler)cleanup to theerrorevent handler inhookRunner.ts. Without this, when a child process emits anerrorevent (e.g., executable not found, spawn failure), the abort listener remains registered on the signal, leaking memory if the same signal is reused across multiple hook executions.Screenshots / Video Demo
N/A — no user-facing UI change. The fix ensures proper cleanup of event listeners on process error.
Dive Deeper
The
closehandler (line 358-364) correctly cleans up both the timeout and the abort listener:But the
errorhandler (line 440-453) only cleared the timeout:Per Node.js docs, when
spawnfails (e.g., executable not found), theerrorevent fires butcloseis NOT guaranteed. So the abort listener remains registered on the signal. If the sameAbortSignalis used for multiple hook executions, stale handlers accumulate.Modified file:
packages/core/src/hooks/hookRunner.ts— Added abort listener cleanup to error handler (4 insertions)Reviewer Test Plan
npx vitest run src/hooks/(all 274 pass)tsc --noEmit(clean)Testing Matrix