vfs/cache: Fix promoteToFast race with WriteCloser Close
CI / vulncheck (pull_request) Successful in 14s
CI / check-and-test (pull_request) Successful in 40s

promoteToFast read FileInfo.Size from Stat after the VFS lock was
released, while WriteCloser.Close updated Size on the same live
object. Concurrent Create/Open on overlapping keys tripped the race
detector.

Stat now returns a FileInfo snapshot, and promotion uses the
ReadAll length for the fast-tier Create size. Promotion stays
best-effort.

#21
This commit is contained in:
s1d3sw1ped_bot
2026-09-01 20:30:40 +00:00
parent 5d006ac44f
commit 8e09c89e24
6 changed files with 94 additions and 8 deletions
+3 -2
View File
@@ -289,7 +289,8 @@ func (m *MemoryFS) Delete(key string) error {
return nil
}
// Stat returns file information
// Stat returns a snapshot of file information. The returned *FileInfo is not
// the live cache entry; Close may update Size on the in-map object under m.mu.
func (m *MemoryFS) Stat(key string) (*types.FileInfo, error) {
if key == "" {
return nil, vfserror.ErrInvalidKey
@@ -310,7 +311,7 @@ func (m *MemoryFS) Stat(key string) (*types.FileInfo, error) {
defer m.mu.RUnlock()
if fi, ok := m.info[key]; ok {
return fi, nil
return fi.Clone(), nil
}
return nil, vfserror.ErrNotFound