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]: DiskCache cleanup holds the global update mutex during filesystem I/O #27360
DiskCache.startUpdateWithCleanup keeps updatingPaths.L locked while invoking its cleanup callback. The production callback from DiskCache.writeFile calls removeUnindexedFile, which can execute filesystem removal (os.Remove). Because the mutex protects the update map for every cache path, a slow cleanup for one path blocks startUpdate, startUpdateWithCleanup, and waitUpdateComplete for unrelated paths as well.
A white-box reproduction ran 3 times: a cleanup callback for path first was held for 150 ms; an update for independent path second remained blocked for the entire interval and proceeded only after cleanup released the global mutex.
Expected Behavior
The per-path update marker should remain held until cleanup completes, but cleanup filesystem I/O should not hold the global mutex for unrelated paths. The implementation should release the global map lock before invoking cleanup, while preserving same-path exclusion and exactly-once marker removal.
Steps to Reproduce
In package pkg/fileservice, create a DiskCache.
Call startUpdateWithCleanup for an IOEntry path with a callback that blocks on a channel.
While the callback is blocked, call startUpdate for a different IOEntry path in another goroutine.
Observe that the independent path cannot start until the first callback returns.
Diagnostic command: GOWORK=off go test -mod=readonly -v -count=3 ./pkg/fileservice -run TestCodexDiskCacheCleanupSerializesIndependentPaths
Additional information
pkg/fileservice/disk_cache.go locks updatingPaths.L in startUpdateWithCleanup, defers its unlock, then runs cleanup() before deleting the path marker and broadcasting.
The production cleanup path is writeFile -> startUpdateWithCleanup -> removeUnindexedFile -> os.Remove.
Under high disk latency, this global critical section can amplify one slow cache cleanup into cluster-wide disk-cache tail latency and waiter buildup across otherwise independent objects.
High-depth cause analysis:\n\nstartUpdateWithCleanup protects a global map of all updating paths with one condition mutex. Its completion function keeps that mutex held while invoking cleanup, and the production cleanup can call os.Remove. Thus the wait-for graph is path A cleanup I/O -> global updatingPaths mutex -> every path B start/wait operation.\n\nThe intended ownership invariant only requires the path A marker to remain true until cleanup completes. It does not require unrelated paths to wait for the cleanup callback. Releasing the global map lock during cleanup, while retaining the marker and performing an exactly-once delete and broadcast afterward, would preserve same-path exclusion and remove this cross-path serialization. With disk p99 in the tens of seconds, this lock scope amplifies one slow cleanup into broad DiskCache tail latency.
Activity
XuPeng-SH commentedon Aug 19, 2026
High-depth cause analysis:\n\nstartUpdateWithCleanup protects a global map of all updating paths with one condition mutex. Its completion function keeps that mutex held while invoking cleanup, and the production cleanup can call os.Remove. Thus the wait-for graph is path A cleanup I/O -> global updatingPaths mutex -> every path B start/wait operation.\n\nThe intended ownership invariant only requires the path A marker to remain true until cleanup completes. It does not require unrelated paths to wait for the cleanup callback. Releasing the global map lock during cleanup, while retaining the marker and performing an exactly-once delete and broadcast afterward, would preserve same-path exclusion and remove this cross-path serialization. With disk p99 in the tens of seconds, this lock scope amplifies one slow cleanup into broad DiskCache tail latency.
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…