Release the transformer once a TransformStream finishes - #7510
Merged
Merged
Conversation
jasnell
added this pull request to stack #7511
September 24, 2026 19:12
Contributor
|
LGTM |
Base automatically changed from
jasnell/ts-streams-transform-cancel-outcome
to
main
September 25, 2026 18:23
jasnell
force-pushed
the
jasnell/ts-streams-transformer-retention
branch
from
September 25, 2026 18:42
3c2e663 to
31239cc
Compare
guybedford
approved these changes
Sep 25, 2026
guybedford
left a comment
Contributor
There was a problem hiding this comment.
The retention fix is right: with the algorithm closures built in makeTransformerAlgorithms, nothing in the constructor's scope references transformer from an inner function (the start() call is direct), so the shared context the interop hooks pin no longer carries it. Verified the gc test collects on all five endings.
One behavioral note on the new dropped-write path (inline), plus two nits:
ClearAlgorithms cleared the cancel and flush algorithms but not the transform algorithm, and all three closures were built in the TransformStream constructor, so `transformer` lived in the constructor's shared context. Every closure the constructor creates keeps that context alive, including the interop error hooks the halves hold for good, so the transformer stayed reachable for as long as the stream did. The algorithms are now built in a module-level helper, which alone captures the transformer, and the transform algorithm lives on the instance beside the other two. ClearAlgorithms drops all three, as the spec has it, and the transformer is collectable after close, abort, cancel, terminate() or error(), with the stream still held. Node agrees; C++ keeps it after close (transform ledger #18). A write that reaches the sink after readable.cancel() cleared the algorithms, before the cancel errors the writable, is left undefined by the spec; like Node, it drops the chunk and fulfills. Behind the experimental typescript_implemented_streams flag.
jasnell
force-pushed
the
jasnell/ts-streams-transformer-retention
branch
from
September 25, 2026 20:25
31239cc to
1495a62
Compare
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.
ClearAlgorithms cleared the cancel and flush algorithms but not the
transform algorithm, and all three closures were built in the
TransformStream constructor, so
transformerlived in the constructor'sshared context. Every closure the constructor creates keeps that context
alive, including the interop error hooks the halves hold for good, so the
transformer stayed reachable for as long as the stream did.
The algorithms are now built in a module-level helper, which alone
captures the transformer, and the transform algorithm lives on the
instance beside the other two. ClearAlgorithms drops all three, as the
spec has it, and the transformer is collectable after close, abort,
cancel, terminate() or error(), with the stream still held. Node agrees;
C++ keeps it after close (transform ledger #17).
A write that reaches the sink after readable.cancel() cleared the
algorithms, before the cancel errors the writable, is left undefined by
the spec; like Node, it drops the chunk and fulfills. Behind the
experimental typescript_implemented_streams flag.