Skip to content

fuse: MountManager.Wait reads m.server unlocked, racing Unmount's write — and can nil-deref #267

Closed

Description

@scttfrdmn

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:

  1. The serving goroutine Mount spawns:
    go func() {
        slog.Info("starting FUSE server")
        m.server.Wait()      // unlocked read of a field Unmount writes
        ...
    }()
  2. 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

  1. added
    type: bug
    priority: high
    area: fuse
    effort: small
    on Aug 3, 2026
  2. added a commit that references this issue on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: fuseeffort: smallpriority: hightype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions