Repository navigation
fix(range-reader): serve reads that arrive as their stream finishes - #861
Merged
Merged
Conversation
A finished stream serves reads its received bytes cover while the reader still holds it, and a lookup reads the cache again when a stream finished while it waited, so neither window sends the bytes again. See #826. Co-Authored-By: Claude Opus 5.5 <[email protected]>
So a read reaches the in-flight streams as soon as it did before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
A read for bytes that a
RangeStreamhad just finished receiving could miss both the stream and the byte cache, and go out as a new request. For COGs, that fetched a header block twice. This closes both windows that #826 describes.Closes #826
Changes
RangeStream.attachserves a finished stream's bytes.settle()marks a stream inactive as soon as its body ends, but the reader keeps it ininflight, and stores its bytes in the cache, only oncerun()resolves. A read arriving in between found the stream and was refused. Now a stream that is done resolves any read its received bytes cover. A read past them is still refused, because a stream that is done never receives more.RangeReaderreads the cache again before queueing a read when a stream finished while the read's first lookup was pending, since that lookup may have run before the stream stored its bytes. A read that misses with no stream finished in the meantime is queued after one lookup, as before.Tests
New tests, each failing on main:
RangeReader, "sends one request when a read arrives as the stream holding its bytes finishes": the issue's repro. A 64 KiB metadata block arrives in one chunk, and the next read is issued from the first one's continuation. Main sends 2 requests.RangeReader, "looks in the cache again when the stream holding a read finishes during its lookup": a cache whose lookup answers after the stream has stored its bytes and left. Main sends 2 requests.RangeStream, "serves only received bytes once cancelled": a cancelled stream serves a read inside the prefix it received, and refuses one past it. Main refuses both.RangeStream, "resolves an attached member when its bytes pass, at once when they already have" now expects a finished stream to serve a read it has the bytes for. Its last assertion said the opposite, which is the bug.Mutation checks, undoing one part of the change at a time:
attachrefuses every read once the stream is doneRangeStreamtests and the reproattachtakes any read once the stream is doneThe issue's Node repro, run against the built
dist:The range-reader, geotiff, deck.gl-raster and deck.gl-geotiff tests pass,
pnpm -r --filter='!docs' typecheckpasses, and Biome is clean.Notes
ByteCacheit doesn't double the lookups of every cold read.lookup. Moving it into an async helper delayed every read's attach by two microtasks.🤖 Written by Claude Code