Repository navigation
fix: the FUSE server field is read under the lock that guards it (#267) - #268
Merged
Merged
Conversation
CI's race detector caught this on the run for #265, a documentation-only pull request — so it was live on main rather than introduced there. `Unmount` writes `m.server = nil` under `m.mu`. Two places read it without the lock: the goroutine `Mount` spawns to serve, and `Wait`. Both are also nil dereferences, which is what makes it more than a detector report. If the unmount lands first, `m.server.Wait()` panics on a background goroutine — unrecoverable, so it takes the process down together with the mount, unmounting under every open file descriptor. `Wait`'s `if m.server != nil` check does not help: the write can land between the check and the dereference. The serving goroutine now waits on the `server` local already in scope. It is the same server either way, and that goroutine's whole job is to outlive the field. `Wait` reads the field into a local under `m.mu` and waits outside it — holding the lock across `server.Wait()` would also silence the detector and would deadlock every real unmount, since `Unmount` needs the same lock to clear the field. Why the suite did not catch it sooner: it reproduces only on Linux and only intermittently. On darwin `fs.Mount` needs macFUSE, so the goroutine never starts and the racing read is unreachable — the local -race suite is green while CI went red once in many runs. A regression test inheriting that property would be worthless, so mount_race_test.go drives both sides directly and needs no mount: one goroutine writes the field under the lock, another calls Wait. Mutation-verified: restoring the unlocked read makes the new test report WARNING: DATA RACE and fail; the fix makes it pass. Gates: go build, go vet, gofmt -l clean, full `go test -count=1 -race` suite green, coverage gate 34 packages at or above floor, golangci-lint --new-from-merge-base=origin/main 0 issues.
Both branches added an [Unreleased] entry; the merge keeps both, ordered Fixed before Changed as Keep a Changelog specifies.
This was referenced Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #267.
Caught by CI's race detector on the run for #265 — a documentation-only PR — so this was live on
main, not introduced by that branch.The defect
Unmountwritesm.server = nilunderm.mu. Two places read it without the lock: the goroutineMountspawns to serve, andWait.Both reads are also nil dereferences, which is what makes this more than a detector report. If
the unmount lands first,
m.server.Wait()panics on a background goroutine — unrecoverable, so ittakes the process down together with the mount, unmounting under every open file descriptor.
Wait'sif m.server != nilguard does not help: the write can land between the check and thedereference.
The fix
The serving goroutine waits on the
serverlocal already in scope — same server either way, andoutliving the field is that goroutine's whole job.
Waitreads the field into a local underm.muand waits outside it.
Holding the lock across
server.Wait()would also silence the detector and deadlock every realunmount, since
Unmountneeds the same lock to clear the field. That trap is recorded inWait'sown comment, because it is the change a future reader is most likely to make.
Why the suite did not catch it sooner, and what that means for the test
It reproduces only on Linux and only intermittently: on darwin
fs.Mountneeds macFUSE, so thegoroutine at
mount.go:247never starts and the racing read is unreachable. The local-racesuiteis green while CI went red once in many runs.
A regression test that inherited that property would be worthless.
internal/fuse/mount_race_test.godrives both sides directly and needs no mount — one goroutine writes
m.server = nilunderm.mu,another calls
Wait()— so it fails deterministically.Mutation-verified: restoring the unlocked read makes the new test report
WARNING: DATA RACEandfail; the fix makes it pass.
Verification
go build ./...·go vet ./...·gofmt -l .empty · fullgo test -count=1 -race ./...green ·coverage gate 34 packages at or above floor ·
golangci-lint --new-from-merge-base=origin/main→ 0issues.