Repository navigation
Description
Branch Name
main
Commit ID
6f42b19508f31ef04ae2857172893f13d48afddf
Other Environment Information
- Reproduction is source-level and does not depend on a particular deployment.
- The same behavior was checked in the fileservice package with
GOWORK=off go test -mod=readonly -count=3. - The affected path is used by CN fileservice disk-cache reads.
Actual Behavior
When an IOEntry disk-cache file is being updated, DiskCache.Read(ctx, ...) waits in waitUpdateComplete. That helper uses sync.Cond.Wait() in a loop but never checks ctx.Done().
After the read context is canceled, the IOEntry read remains blocked until the unrelated cache update releases the path. In the diagnostic reproduction, it was still blocked 150ms after cancellation and only returned after the update was released. Under a stalled disk-cache update, this can retain canceled request goroutines and their buffers for the entire update duration.
The same method has an asymmetric control path: full-file fallback uses waitUpdateCompleteFor, which checks both the context and a bounded timeout, and returned promptly in the control test.
Expected Behavior
A canceled DiskCache.Read should stop waiting for an in-progress IOEntry disk-cache update and return promptly, with the same cancellation/bounded-wait contract as the full-file fallback. The wait must not retain a canceled request indefinitely.
Steps to Reproduce
Add a temporary white-box test under pkg/fileservice:
cache, _ := NewDiskCache(context.Background(), t.TempDir(),
fscache.ConstCapacity(1<<20), nil, false, nil, "")
defer cache.Close(context.Background())
path := cache.pathForIOEntry("foo", IOEntry{Offset: 0, Size: 1})
release := cache.startUpdate(path)
ctx, cancel := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() {
v := &IOVector{FilePath: "foo",
Entries: []IOEntry{{Offset: 0, Size: 1}}}
done <- cache.Read(ctx, v)
}()
// Wait until Read has entered waitUpdateComplete, then:
cancel()
select {
case <-done:
// unexpected: the read returned before the update was released
case <-time.After(150 * time.Millisecond):
// observed: the read is still blocked
}
release()
// Read returns only after this release.Run:
GOWORK=off go test -mod=readonly -v -count=3 -timeout 60s ./pkg/fileservice -run '^TestCodexDiskCache(IOEntryWaitIgnoresCancellation|FullFileWaitHonorsCancellation)$'Observed on all three runs:
- IOEntry wait remained blocked after cancellation.
- Releasing the update unblocked the read.
- The full-file control returned within the 500ms control bound.
Relevant code:
pkg/fileservice/disk_cache.go:333callswaitUpdateComplete(ctx, diskPath).pkg/fileservice/disk_cache.go:669-677waits on the condition variable without checking the context.pkg/fileservice/disk_cache.go:679-710implements the bounded, context-aware full-file wait.
Additional information
This is a deterministic white-box counterexample of an asymmetric cancellation contract. The issue becomes operationally significant when disk-cache update latency is high or an update fails to complete. A fix should preserve the condition-variable wakeup behavior while making the wait context-aware and should include cancellation, update-release, and stalled-update tests.
Activity
XuPeng-SH commentedon Aug 19, 2026
Additional white-box control on the same commit:
DiskCache.Update(ctx, ...)has the same cancellation gap on the writer side.writeFilecallsstartUpdateWithCleanup, whose condition-variable loop also ignores the context. Holding the path withcache.startUpdate(path), starting an Update with a cancellable context, and canceling it left Update blocked for 150ms; releasing the held update then unblocked it. This reproduced 3/3 runs.The temporary diagnostic test now covers:
The shared fix should therefore cover both
waitUpdateCompleteandstartUpdateWithCleanup, or otherwise define and test a single context-aware update-path wait contract.XuPeng-SH commentedon Aug 19, 2026
Impact clarification:
DiskCache.waitUpdateCompletewithout observing the request context. If the concurrent cache update is slow, a canceled or timed-out SQL/RPC request can retain its execution goroutine/task until the update completes; if the filesystem stalls, the wait can be unbounded.DiskCache.Updatecan also remain blocked after cancellation instartUpdateWithCleanup; the shared cancellation/waiting design should be reviewed.XuPeng-SH commentedon Aug 19, 2026
Additional white-box reproduction:
DiskCache.DeletePathsis also blocked bystartUpdateafter its context is canceled when the same full-file path is being updated; it returned only after the held update was released, reproduced 3/3. This is the same missing-context termination edge as the IOEntry read and writer paths, not a separate root cause.XuPeng-SH commentedon Aug 19, 2026
High-depth cause analysis:\n\n1. DiskCache.Read tries the IOEntry cache path before the full-file fallback. The IOEntry branch calls waitUpdateComplete, whose condition-variable loop has no context or deadline.\n2. A writer marks the same path as updating before writeFile and clears it only after all write work and cleanup finish. writeFile includes io.CopyBuffer and f.Sync, neither of which provides a context cancellation edge for a blocked local disk operation.\n3. Therefore a slow or stuck disk write leaves the path marker true. Canceled readers, writers, and DeletePaths callers remain waiters until the physical update eventually releases the marker. The full-file fallback is different because waitUpdateCompleteFor polls context and timeout.\n4. High disk latency plus the ignored async flag in #27359 turns this into a fan-in point: many SQL/RPC requests can retain goroutines, task state, and buffers behind the same cache path. This is a Q2 termination failure with a direct tail-latency and resource-accumulation path.\n\nThe missing termination edge is not in the caller context; it must be added to the update-path wait itself, while preserving same-path exclusion and exactly-once release.
fix(fileservice): harden disk cache async update lifecycle (#27368)
fix(fileservice): harden disk cache async update lifecycle (matrixori…
fix(fileservice): harden disk cache async update lifecycle (matrixori…
fix(fileservice): harden disk cache async update lifecycle (matrixori…