Repository navigation
Description
Caught by CI's race detector on the run for #265 — a docs-only PR — which means it is a live defect on
main, not something that PR introduced.
The race
internal/fuse/mount.go writes m.server under m.mu in Unmount:
m.mu.Lock()
m.mounted = false
m.server = nil
m.mu.Unlock()and read it without the lock in two places:
- The serving goroutine
Mountspawns:go func() { slog.Info("starting FUSE server") m.server.Wait() // unlocked read of a field Unmount writes ... }()
Wait:func (m *MountManager) Wait() { if m.server != nil { m.server.Wait() // unlocked read, and a TOCTOU on the nil check } }
The detector's report from run 30826317883:
WARNING: DATA RACE
Write at 0x00c00046af90 by goroutine 122:
internal/fuse.(*MountManager).Unmount() mount.go:322
internal/adapter.(*Adapter).Stop() adapter.go:280
Previous read at 0x00c00046af90 by goroutine 234:
internal/fuse.(*MountManager).Mount.func1() mount.go:249
Why it is worse than a race report
Both sites are also nil dereferences. If Unmount wins, m.server is nil and m.server.Wait()
panics — on a background goroutine, so it is unrecoverable and takes the process down together with
the mount, unmounting under every open file descriptor. In Wait the nil check does not help,
because the write can land between the check and the dereference.
This is the class RACE_CONDITION_AUDIT.md declared eliminated repo-wide before that document was
deleted for exactly this reason.
Why the test suite did not catch it sooner
It reproduces only intermittently, and only on Linux. On darwin fs.Mount needs macFUSE, so the
goroutine at mount.go:247 never starts and the racing read is unreachable — which is why the local
-race suite is green while CI went red once in many runs.
Fix
Wait on the local server variable already in scope rather than re-reading the field, and in Wait
read the field into a local under m.mu before dereferencing. Holding the lock across server.Wait()
would silence the detector and deadlock every real unmount, since Unmount needs the same lock to
clear the field — so the read is synchronized and the wait is not.
Verification
A regression test must fail deterministically, not once per many runs. internal/fuse/mount_race_test.go
drives both sides directly and needs no mount: one goroutine writes m.server = nil under m.mu,
another calls Wait(). Mutation-verified — restoring the unlocked read makes it report WARNING: DATA RACE and fail; the fix makes it pass.
Activity
fix: the FUSE server field is read under the lock that guards it (#267)…
Merge origin/main: fold #267's Fixed entry in beside #169's