Repository navigation
fix(geotiff): stop one aborted or failed header read from failing other tiles - #709
Merged
Merged
Conversation
GeoTIFF.fromUrl cached header reads with chunkd's SourceCache, which keeps a read's promise even when it rejects and returns that rejection to every later read of the same range (blacha/chunkd#1733). So one aborted or failed request for a chunk of the TileOffsets/TileByteCounts tables failed every later tile whose entries sit in that chunk, for the life of the GeoTIFF. Replace it with CacheMiddleware, adapted from SourceCache, which evicts a read that fails so the next reader retries it. Eviction checks the entry's identity, so a stale failure never removes a newer read of the same range. Part of #690. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r read Each tile fetch looks up its byte range with image.getTileSize, which on a large COG reads its TileOffsets/TileByteCounts entries lazily through the cached header source, so all tiles with entries in one chunk share one request. The tile's signal was forwarded into that shared request, so aborting one tile (e.g. panning it out of view) rejected the request for every other tile waiting on it, even with failed reads evicted. Look up byte ranges through getTileByteRange instead, in fetchTile, fetchTiles, and the band-separate path. The shared read runs without the caller's signal; the signal only ends that caller's wait, rejecting with signal.reason at once. Reads during open keep their signal: that cache belongs to one open, so nothing else shares its reads. The trade-off: a header read whose tiles all aborted still completes and holds its limiter slot until it does. That happens at most once per chunk, and neighboring tiles usually need those bytes. The regression tests build a GeoTIFF in memory whose tile tables run past the first 64 KiB chunk, since no fixture has a header that large. Part of #690. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name the cache by its eviction strategy: an approximate LRU bounded by bytes, using the two-generation scheme of hashlru and quick-lru (the same one chunkd's SourceCache uses). The docstring now leads with that strategy and what the approximation means in practice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
commented
Oct 14, 2026
Comment on lines
+16
to
+18
| * chunkd middleware that caches each read by its byte range in an | ||
| * approximate LRU cache bounded by bytes, so concurrent and later reads of a | ||
| * range share one request. |
Member
Author
There was a problem hiding this comment.
Suggested change
| * chunkd middleware that caches each read by its byte range in an | |
| * approximate LRU cache bounded by bytes, so concurrent and later reads of a | |
| * range share one request. | |
| * Middleware that caches each read by its byte range in an | |
| * approximate LRU cache. Concurrent and later reads of a | |
| * range share one request. |
kylebarron
commented
Oct 14, 2026
| options?: { signal?: AbortSignal }, | ||
| ): Promise<ByteRange> { | ||
| const signal = options?.signal; | ||
| if (signal?.aborted) { |
Member
Author
There was a problem hiding this comment.
We should have a comment here saying that this is the main change from upstream, IIUC. If the signal was aborted, we reject the promise, right?
| * Look up a tile's byte range: its `TileOffsets` and `TileByteCounts` | ||
| * entries. | ||
| * | ||
| * When those tables don't fit in the bytes read at open, cogeotiff reads each |
Member
Author
There was a problem hiding this comment.
Suggested change
| * When those tables don't fit in the bytes read at open, cogeotiff reads each | |
| * When those tables don't fit in the bytes read at open, TiffImage reads each |
Mark where the lookup departs from upstream cogeotiff, whose getTile forwards the caller's signal into the shared read, and comment the already-aborted check and the race. Link TiffImage in the docstring. 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.
On a COG whose
TileOffsets/TileByteCountstables extend past the first 64 KiB header chunk, each tile fetch reads its two table entries lazily through the cached header source, so every tile with entries in one chunk shares one request. Two problems let one tile break that shared request for every other tile, for the life of theGeoTIFF:SourceCachekeeps a read's promise even when it rejects (SourceCache keeps a rejected promise, so one aborted or failed read is replayed to every later reader blacha/chunkd#1733), so one aborted or failed request was replayed to every later tile in that chunk, with no new request.deck.gl marks a tile whose read fails, without the tile itself being cancelled, as loaded with no content and never retries it, so these tiles stayed blank.
Changes:
GeoTIFF.fromUrlcaches header reads with a newLRUCacheMiddlewarein place ofSourceCache. It uses the same approximate LRU scheme asSourceCache, but drops a read that fails so the next reader retries it.fetchTile,fetchTilesand the band-separate path look up byte ranges with a newgetTileByteRange. The shared read runs without the caller's signal; the signal only ends that caller's wait, rejecting withsignal.reasonat once (previously aSourceErrorwrapping it).Trade-off: a header read whose tiles all aborted now still completes and holds its limiter slot until it does. That happens at most once per chunk per file, and neighboring tiles usually need those bytes. Refcounted cancellation would avoid it, but would mean replacing chunkd's chunking and caching to save a handful of small reads.
Tests:
shared-header-reads.test.tscovers each failure mode from the issue: an abort mid-request, a tile joining an in-flight read (through each of the three call sites), an abort while queued in the limiter, a transient 503, and the abort reason. It builds the GeoTIFF in memory, since no existing fixture has tile tables past the first chunk.cache.test.tscovers the cache's eviction.Closes #690
Written by Claude on behalf of @kylebarron.
🤖 Written by Claude Code