Skip to content

fs/vfs: fix data race between the statfs goroutine and the timeout - #3938

Open
thc1006 wants to merge 1 commit into
google:masterfrom
thc1006:vfs-stats-timeout-race
Open

thc1006 wants to merge 1 commit into
google:masterfrom
thc1006:vfs-stats-timeout-race

Conversation

@thc1006

@thc1006 thc1006 commented Sep 26, 2026 •

Copy link
Copy Markdown

GetVfsStats runs statfs in a goroutine and gives up after two seconds. The goroutine assigns the function's named results, and the timeout branch writes zero values into the same variables on its way out. When the timeout path returns without receiving the worker's result, those writes are not synchronized.

Kubernetes runs its kubelet with the race detector in the pull-kubernetes-kind-dra-all job, and that job has reported it in eight runs between September 21 and 26 as write/write races between stats.go:59 and the goroutine's assignments, one per result, most recently in this run with lib v0.60.6.

The goroutine now fills a local result and hands it over on the channel. It no longer touches the caller's variables.

The syscall and the timeout become package variables. The tests stub statfs with known values, and the timeout case runs under testing/synctest with fake time, where the worker finishes after the caller has returned and must exit without touching the results. That test fails with -race on the current code and passes with this change. The normal path is unchanged, including the zero values that come back together with a statfs error.

A hung statfs still blocks its goroutine until the syscall returns, as before. This change removes the race, not that.

This PR was written in part with the assistance of generative AI.

Fixes #3937.

GetVfsStats assigns its named results from the goroutine that calls
statfs, and the timeout branch writes the same variables on its way
out. When the timeout path returns without receiving the worker's
result, those writes are not synchronized. The Kubernetes kubelet,
built with -race, reports this as six write/write races at stats.go:59
whenever the timeout path is taken before the worker has finished.

Fill a local result in the goroutine and send only that over the
channel. Make the syscall and the timeout package variables so that
tests can stub statfs with known values and run the timeout case under
testing/synctest, where the worker finishes after the caller has
returned without depending on wall-clock scheduling.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@thc1006
thc1006 force-pushed the vfs-stats-timeout-race branch from 21ad720 to 8162e14 Compare September 26, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs/vfs: GetVfsStats timeout races with writes to named return values

1 participant