From f15291e85712246ea6f5b6ad98c1d7509cd7e039 Mon Sep 17 00:00:00 2001 From: Matthew Mattox Date: Fri, 13 Nov 2026 22:34:21 -0600 Subject: [PATCH] test: retry busy unmounts and detach a killed mount MountedFS.Unmount ran fusermount -u once. When anything still used the mount, for a FUSE release in flight or a desktop indexer crawling it, it logged the EBUSY, killed the daemon after 10s, and reported success. The dead mount then made the next Mount at that path time out. On .68 with mounts under $HOME, GNOME's localsearch kept them busy for about 110 ms, and TestFsckRepairsOlderSharing failed every run this way. Unmount now retries fusermount -u while it reports busy, for up to 10s. If the mount stays busy, it kills the daemon, detaches the dead mount with fusermount -uz, and returns the error. Co-Authored-By: Claude Opus 5.5 --- tests/integration/helpers.go | 50 ++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/tests/integration/helpers.go b/tests/integration/helpers.go index 984d90dd..61e1c063 100644 --- a/tests/integration/helpers.go +++ b/tests/integration/helpers.go @@ -332,23 +332,38 @@ func (m *MountedFS) WaitForMount(timeout time.Duration) error { return fmt.Errorf("timeout waiting for mount after %v", timeout) } -// Unmount unmounts the filesystem using fusermount. +// unmountBusyTimeout is how long Unmount retries fusermount while the mount is +// busy: a FUSE release still in flight after close, or a desktop indexer +// crawling the mount, keeps it busy for a moment. +const unmountBusyTimeout = 10 * time.Second + +// Unmount unmounts the filesystem and waits for the mount process to run its +// clean shutdown. If the mount stays busy, it kills the process and detaches +// the dead mount, so a later Mount at the same path can work, and returns an +// error. func (m *MountedFS) Unmount() error { - // Use fusermount to unmount FIRST. - // This triggers the go-fuse server to exit cleanly, allowing - // the mount command to run its shutdown code (journal checkpoint, etc.) - // Do NOT cancel the context first - that would SIGKILL the process - // and skip the clean shutdown path where journal checkpointing happens. - cmd := exec.Command("fusermount", "-u", m.MountPoint) - output, err := cmd.CombinedOutput() - if err != nil { - // May fail if already unmounted - m.t.Logf("fusermount output: %s", output) + var unmountErr error + start := time.Now() + for busy := 0; ; busy++ { + output, err := exec.Command("fusermount", "-u", m.MountPoint).CombinedOutput() + if err == nil || !m.IsMounted() { + unmountErr = nil + if busy > 0 { + m.t.Logf("fusermount -u succeeded after the mount was busy for %v", time.Since(start).Round(time.Millisecond)) + } + break + } + unmountErr = fmt.Errorf("fusermount -u %s: %v: %s", m.MountPoint, err, strings.TrimSpace(string(output))) + if !strings.Contains(string(output), "busy") || time.Since(start) > unmountBusyTimeout { + m.t.Log(unmountErr) + break + } + time.Sleep(100 * time.Millisecond) } - // Wait for mount process to exit cleanly + // Do not cancel the context first: that kills the process before its + // clean shutdown checkpoints the journal. if m.MountCmd != nil && m.MountCmd.Process != nil { - // Give it time to run clean shutdown (journal checkpoint, etc.) done := make(chan error, 1) go func() { done <- m.MountCmd.Wait() @@ -360,7 +375,6 @@ func (m *MountedFS) Unmount() error { m.t.Logf("mount process exited: %v", err) } case <-time.After(10 * time.Second): - // Force kill only as last resort after generous timeout m.t.Log("Warning: mount process did not exit in time, force killing") if m.cancel != nil { m.cancel() @@ -369,6 +383,14 @@ func (m *MountedFS) Unmount() error { } } + if m.IsMounted() { + if output, err := exec.Command("fusermount", "-uz", m.MountPoint).CombinedOutput(); err != nil { + m.t.Logf("fusermount -uz %s: %v: %s", m.MountPoint, err, output) + } + } + if unmountErr != nil { + return unmountErr + } m.t.Log("Unmounted successfully") return nil }