vfs/cache: Fix promoteToFast race with WriteCloser Close #23

Merged
Ghost merged 1 commits from vfs/cache-promote-race into develop 2026-09-01 15:35:20 -05:00

What

Stat returns a FileInfo snapshot (MemoryFS and DiskFS). promoteToFast uses that snapshot only for space/ReadAll guards, then creates in the fast tier with len(content) so it never reads a live FileInfo.Size while WriteCloser.Close updates Size.

Why

Main push CI failed with DATA RACE: memoryWriteCloser.Close writing fi.Size vs promoteToFast reading info.Size after Stat returned the live map entry. Same package run also race-failed PromotionFallback.

Test

go test -race -count=20 -shuffle=on ./vfs/cache green locally (Concurrent + PromotionFallback). Also held under -count=100.

#21

## What Stat returns a FileInfo snapshot (MemoryFS and DiskFS). promoteToFast uses that snapshot only for space/ReadAll guards, then creates in the fast tier with len(content) so it never reads a live FileInfo.Size while WriteCloser.Close updates Size. ## Why Main push CI failed with DATA RACE: memoryWriteCloser.Close writing fi.Size vs promoteToFast reading info.Size after Stat returned the live map entry. Same package run also race-failed PromotionFallback. ## Test `go test -race -count=20 -shuffle=on ./vfs/cache` green locally (Concurrent + PromotionFallback). Also held under -count=100. https://git.s1d3sw1ped.com/s1d3sw1ped/steamcache2/issues/21
Ghost added 1 commit 2026-09-01 15:32:09 -05:00
vfs/cache: Fix promoteToFast race with WriteCloser Close
CI / vulncheck (pull_request) Successful in 14s
CI / check-and-test (pull_request) Successful in 40s
8e09c89e24
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
Ghost merged commit 523a9a4782 into develop 2026-09-01 15:35:20 -05:00
Ghost deleted branch vfs/cache-promote-race 2026-09-01 15:35:20 -05:00
Sign in to join this conversation.