Repository navigation
fix(sdk): release completed embedded request signals - #53613
Merged
Merged
Conversation
This was referenced Oct 6, 2026
3 of 6 tasks
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.
Why
Long-lived embedded SDK hosts leak every completed
Request,Headers,AbortSignal, and request body buffer untilclose()is called.OwnedFetch.makepreviously bound each request toAbortSignal.any([source.signal, shutdown.signal]), and Effect's web handler (HttpEffect.toWebHandler*) registers anabortlistener onrequest.signalwithout removing it when the request completes normally. Becauseshutdown.signalstayed live for the lifetime of the host, the dependent signal and its abort listener remained reachable after response consumption and GC.What Changes
Before:
OwnedFetch.makekept a host-lifetimeshutdownAbortControllerand constructedAbortSignal.any([source.signal, shutdown.signal])for every request.shutdown.signalretained the dependentrequest.signaland the Effect web handler'sRequestclosure for the lifetime of the host (200client.server.info()calls retained 201Requestinstances after GC).After:
OwnedFetch.maketracks active requests inMap<AbortController, Promise<void>>instead of maintaining a host-levelshutdownAbortController.source.signalaborts to its per-requestcontrollerand detaches that listener infinish()when the response completes, cancels, or rejects.close()aborts only the active controllers currently inrequestsand awaits their lifetimes before disposing the runtime.Scope
This PR updates
OwnedFetch.makeinpackages/sdk/src/internal/fetch.tsand adds embedded request-retention and cancellation tests inpackages/sdk/test/request-retention.test.ts.Verification
test/request-retention.test.ts: Failed onorigin/v2with 201 retainedRequestobjects after 200client.server.info()calls and 120/120 retainedRequestobjects on the failure path; all 4 tests pass with this change.bun typecheckinpackages/sdkand repo-widebun run checkpass.