Release the caller abort listener in getTimeoutPromise#1640
Merged
Conversation
getTimeoutPromise registered an abort listener on the caller's AbortSignal but never removed it. This change registers the listener with an auto-cleanup signal option and aborts the inner controller in finally, matching the pattern already used by the other three confirmation strategies in this package.
🦋 Changeset detectedLatest commit: 55c9a31 The changes in this PR will be included in the next version bump. This PR includes changesets to release 47 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
BundleMonFiles updated (4)
Unchanged files (143)
Total files change +77B +0.01% Final result: ✅ View report in BundleMon website ➡️ |
Contributor
Author
|
@kit-content-writer @steveluscher @beeman @alessandrod @ChALkeR @mcintyre94 |
mcintyre94
approved these changes
May 18, 2026
This was referenced May 18, 2026
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.
Summary
getTimeoutPromisein@solana/transaction-confirmationregisters anabortlistener on the caller suppliedAbortSignalbut never removes it. When a caller reuses the same signal across multiple calls, listeners accumulate. This change brings the function in line with the auto-cleanup pattern already used by the three sibling confirmation strategies in the same package.Before
The third argument to
addEventListeneris omitted. There is no matchingremoveEventListener, so the listener stays attached for the lifetime of the caller signal regardless of how the promise settles.After
getTimeoutPromisenow creates an innerAbortController, registers the caller signal listener with{ signal: innerController.signal }, and aborts the inner controller in afinallyblock. The platform releases the listener automatically when the inner controller aborts. ThesetTimeouthandle is also cleared infinallyso that the underlying timer is released on every exit path.This is the same pattern already used by:
confirmation-strategy-recent-signature.ts:87confirmation-strategy-racer.ts:28confirmation-strategy-blockheight.ts:89Before this change,
confirmation-strategy-timeout.tswas the only file in the package that deviated from this convention.Behavioral impact
None for callers. The function still throws a
TimeoutErrorwhen the timeout elapses and anAbortErrorwhen the caller signal aborts, exactly as documented. The four existing tests pass unchanged.The leak itself is silent in the common case (a fresh
AbortControllerper confirmation) but surfaces when callers reuse a long-lived signal across many timeout calls. In Node this can produce aMaxListenersExceededWarningonce the listener count crosses the implicit cap. In any runtime it grows memory proportionally to the number of calls made.Tests
Three new tests cover the cleanup contract:
registers the caller abort listener with an auto-cleanup signalverifies synchronously that the listener is registered with thesignaloption.aborts the cleanup signal once the timeout elapsesverifies that the inner cleanup signal aborts after the timeout fires, releasing the listener.aborts the cleanup signal when the caller abortsverifies the same on the caller abort path.The four existing tests in
confirmation-strategy-timeout-test.tscontinue to pass without modification.Closes
Closes #1639