You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: SetAsyncUpdate(true) does not make disk-cache updates asynchronous #27359
CachingFileService.SetAsyncUpdate(true) is documented as setting cache updates to asynchronous mode, and LocalFS/S3FS pass their asyncUpdate flag into DiskCache.Update. However, DiskCache.Update never uses the async argument. It enters writeFile, whose startUpdateWithCleanup waits on an existing update for the same cache path. Therefore an async=true update still blocks its caller behind a slow or stuck disk-cache update.
A white-box reproduction ran 3 times. With an existing update held for the same IOEntry path, DiskCache.Update(..., async=true) remained blocked for at least 150 ms and returned only after the held update was released.
Expected Behavior
When asynchronous update is enabled, the caller should not synchronously wait for disk-cache I/O or an in-progress update. The implementation should enqueue or otherwise schedule the update with explicit ownership/lifetime handling for the vector data, and define close/error/cancellation behavior. async=false may retain synchronous behavior.
Steps to Reproduce
In package pkg/fileservice, create a DiskCache.
Hold cache.startUpdate(cache.pathForIOEntry("foo", IOEntry{Offset: 0, Size: 1})).
Start cache.Update(ctx, &IOVector{FilePath: "foo", Entries: []IOEntry{{Offset: 0, Size: 1, Data: []byte("x")}}}, true) in a goroutine.
Observe that it remains blocked until the held update is released.
Diagnostic command: GOWORK=off go test -mod=readonly -v -count=3 ./pkg/fileservice -run TestCodexDiskCacheAsyncFlagStillWaits
Additional information
The public interface comment is in pkg/fileservice/caching_file_service.go: SetAsyncUpdate sets cache update operation to async mode.
LocalFS and S3FS default asyncUpdate to true and pass it to their disk-cache update calls.
pkg/fileservice/disk_cache.go accepts the flag but does not branch on it; startUpdateWithCleanup waits in a condition-variable loop.
Under disk-cache p99 latency or a stalled filesystem, this can turn a cache optimization into synchronous request blocking and contribute to tail-latency and waiter buildup.
High-depth cause analysis:\n\nThe public SetAsyncUpdate contract is not connected to an asynchronous execution boundary for DiskCache. LocalFS and S3FS default asyncUpdate to true and pass it into DiskCache.Update from deferred Read cleanup, but DiskCache.Update never branches on async. It enters writeFile directly, then performs same-path exclusion, file copy, f.Sync, rename, and cache index updates on the caller stack.\n\nThis creates two effects: the advertised async mode adds the complete disk write latency to Read completion, and a canceled Read can continue synchronous cache work after its request is no longer useful. The missing queue or worker ownership model also means there is no defined bound for pending async work, no data-lifetime transfer, and no close/error completion contract. The deterministic white-box wait reproduction proves the flag is not merely an implementation detail: async=true and the existing-update wait have the same synchronous behavior.
Activity
XuPeng-SH commentedon Aug 19, 2026
High-depth cause analysis:\n\nThe public SetAsyncUpdate contract is not connected to an asynchronous execution boundary for DiskCache. LocalFS and S3FS default asyncUpdate to true and pass it into DiskCache.Update from deferred Read cleanup, but DiskCache.Update never branches on async. It enters writeFile directly, then performs same-path exclusion, file copy, f.Sync, rename, and cache index updates on the caller stack.\n\nThis creates two effects: the advertised async mode adds the complete disk write latency to Read completion, and a canceled Read can continue synchronous cache work after its request is no longer useful. The missing queue or worker ownership model also means there is no defined bound for pending async work, no data-lifetime transfer, and no close/error completion contract. The deterministic white-box wait reproduction proves the flag is not merely an implementation detail: async=true and the existing-update wait have the same synchronous behavior.
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…