fix(multiapp): serve ReadAt from a detached handle on cache eviction race - #2104
Merged
Merged
Conversation
…race A foreground ReadAt cache-miss opens and caches a chunk via singleflight, then re-acquires it from the cache to take its ref. A concurrent insert (another foreground miss or a background prefetch) could evict or replace that just-inserted entry in between, so the re-acquire returned cache.ErrKeyNotFound and ReadAt failed with a spurious "key not found" for a perfectly valid, readable offset. This surfaced as flaky failures in embedded/appendable/remoteapp.TestWritePastFirstChunk (~3/8 full-package runs), introduced by the parallel-prefetch / range-fetch read path. Fix: when the post-open re-acquire misses, the data is still readable, so re-open a detached, self-closing handle (refs=1, evicted) for that single read instead of erroring. The detached handle is released exactly once by ReadAt, which performs the underlying Close, so there is no leak. Adds TestMultiAppConcurrentReadEvictionRace, which deterministically reproduces the race (small cache + prefetch + concurrent sequential readers) — 10/10 "key not found" before the fix, 0/20 after, clean under -race.
Collaborator
vchaindz
force-pushed
the
fix/multiapp-readat-keynotfound-race
branch
from
June 26, 2026 07:56
a544f01 to
9b383b3
Compare
SimoneLazzaris
approved these changes
Jul 30, 2026
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.
Problem
The tag CI for v1.11.1 failed on a flaky unit test:
This is unrelated to the v1.11.1 SQL-panic fix (#2100) — that PR only touched
embedded/sql/*andpkg/database/*. The failure lives in the remote/multi appendable read path introduced by the recent parallel-prefetch / range-fetch ReadAt work, and reproduces ~3/8 full-package runs ofembedded/appendable/remoteapp.Root cause
In
multiapp.appendableFor(), a foregroundReadAtcache-miss:Puts it into the fixed-capacity LRU cache via singleflight, thenGet) to take its refcount.A concurrent insert — another foreground miss or a background prefetch goroutine — can evict or
Replacethat just-inserted entry between steps 1 and 2. The re-acquire then returnscache.ErrKeyNotFound, andReadAtfails with a spuriouskey not foundfor a perfectly valid, readable offset.Fix
When the post-open re-acquire misses, the data is still readable (locally or remotely), so re-open a detached, self-closing handle (
refs=1, evicted) for that single read instead of erroring.ReadAtalreadyRelease()s the handle exactly once, which performs the underlyingClose— no leak, no cache entry to govern its lifetime.Test
Adds
TestMultiAppConcurrentReadEvictionRace(small cache + prefetch + concurrent sequential readers), which deterministically reproduces the race:key not found-raceVerification:
embedded/appendable/multiapp— 0/10 full-package failures,-racecleanembedded/appendable/remoteapp— was ~3/8, now 0/15,-racecleanembedded/storegreen;go build ./...andgo vetclean