Repository navigation
Conversation
Stream readers only released their lock on abort, early `break`/`return`, or a read error, so the source stream stayed registered and kept buffering chunks nobody would read until the trailer arrived. Cancel the stream instead, which unregisters it via the source `cancel` hook so later packets are dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 1c2e4cf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
1egoman
added this pull request to stack #2169
October 20, 2026 22:00
Contributor
size-limit report 📦
|
lukasIO
approved these changes
Oct 21, 2026
This branch has not been deployed
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.
Stacked on #2167. Follow-up to this review thread.
#2167 unregisters an incoming data stream when its source
ReadableStreamis cancelled. But when a consumer stops reading early,TextStreamReaderandByteStreamReaderonly callreleaseLock(), which doesn't cancel the stream. A consumer stops early by aborting thesignalpassed toreadAll/withAbortSignal, by leaving afor awaitwithbreak/return, or when the reader throws one of its own errors (for example, more bytes thantotalLength). The stream then stays registered, and later chunks pile up in a queue nobody reads until the trailer arrives or the sender disconnects. On uncompressed streams nothing caps that buffering.This PR makes the iterator's early-exit cleanup call
reader.cancel(reason)before releasing the lock. The cancel travels up the pipe chain to the source stream, and thecancelhook from #2167 removes the stream fromtextStreamControllers/byteStreamControllers. Later packets for that stream are dropped as if it had never been opened. Streams that finish normally never run this cleanup, so they aren't affected. This also matches how the built-inReadableStreamasync iterator behaves on early exit.Behavior change: before this change, each
[Symbol.asyncIterator]()call took a fresh lock, so a consumer couldbreakout of afor awaitand resume the same stream later. That is no longer possible: once a reader stops early, the stream is cancelled. This wasn't documented, and I don't expect anyone to rely on it, but the changeset calls it out.Testing
readAllpartway through, then checks that a late chunk is dropped and that a header reusing the stream ID opens a fresh stream, before any trailer for the old stream has arrived. It fails without theStreamReaderchange.vitest: all tests pass exceptsmoke-tests/smoke.spec.ts, which fails with a missing@playwright/testimport and fails the same way on the base branch.tsc --noEmitand eslint are clean.🤖 Generated with Claude Code