Skip to content

Stop fusermount hanging when the mount helper passes no device - #209

Open
dsfaccini wants to merge 1 commit into
jacobsa:masterfrom
dsfaccini:upstream/mount-helper-socket
Open

dsfaccini wants to merge 1 commit into
jacobsa:masterfrom
dsfaccini:upstream/mount-helper-socket

Conversation

@dsfaccini

Copy link
Copy Markdown

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Summary

fusermount starts the mount helper with one end of a socket pair as fd 3, then reads the device from the other end (mount.go L131-L233). It keeps its own copy of the helper's end open until it returns (defer writeFile.Close(), L146). When the helper exits without passing a device, the read in ReadMsgUnix (L196) never sees EOF, because this process still holds the other end. Mount hangs forever.

  • With wait false, as for the macFUSE 4 mount helper (mount_darwin.go L198-L213, L230-L237), the read runs while the helper runs. A helper that exits without passing a device, with any exit status, hangs Mount.
  • With wait true, as for fusermount3 on Linux (mount_linux.go L153), cmd.Run returns a nonzero exit status as an error before the read. Only a helper that exits with status 0 without passing a device hangs Mount.

This PR changes fusermount:

  • It closes its copy of the helper's end as soon as the helper has started. A helper that exits without passing a device now makes fusermount fail at ReadMsgUnix with EOF.
  • It creates the socket pair close-on-exec under syscall.ForkLock, as the net package creates sockets on darwin (sysSocket in net/sys_cloexec.go). syscall.Socketpair returns descriptors without close-on-exec, so the helper inherited both ends at their original numbers besides fd 3, and so did any child that another goroutine forked meanwhile. Such a child holds a copy of the helper's end, and keeps the read from ending until it exits. exec.Cmd still passes the helper its end as fd 3.
  • With wait false, nothing waited for the helper, so it stayed a zombie for the life of the process, one per mount. fusermount now reaps it in a background goroutine.

I have not run this against mount_macfuse or fusermount3. The tests use a fake helper. I have not checked when the real helpers exit without passing a device.

Tests

None of the tests mounts. They run the test binary as the mount helper: TestFakeMountHelper acts as one when FUSE_TEST_FAKE_MOUNT_HELPER is set, and skips otherwise. Run them with:

go test -run '^(TestFakeMountHelper|TestFusermountFailsWhenTheHelperPassesNoDevice|TestMountHelperInheritsOnlyItsEndOfTheSocket)$' .
  • TestFusermountFailsWhenTheHelperPassesNoDevice, with wait true and false: the helper exits with status 0 without passing a device. fusermount must fail at ReadMsgUnix with EOF.
  • TestMountHelperInheritsOnlyItsEndOfTheSocket: the helper exits with status 1 when it inherited a socket other than fd 3 and the sockets the test process already held. Otherwise it passes /dev/null back as the device. fusermount runs it with wait true and must succeed.

The tests set no timeout of their own; each helper run gets -test.timeout=1m. On master (a124548), each subtest of the first test blocks in ReadMsgUnix until go test -timeout ends it (excerpt, paths shortened):

=== RUN   TestFusermountFailsWhenTheHelperPassesNoDevice
=== RUN   TestFusermountFailsWhenTheHelperPassesNoDevice/wait=false
panic: test timed out after 20s
...
goroutine 36 [IO wait]:
...
net.(*UnixConn).ReadMsgUnix(...)
github.com/jacobsa/fuse.fusermount(...)
	mount.go:196 +0x65c
github.com/jacobsa/fuse.runFakeMountHelper(...)
	mount_helper_test.go:42 +0xa0
...
FAIL	github.com/jacobsa/fuse	20.176s

On master, the helper of the second test inherits a socket of the pair:

=== RUN   TestMountHelperInheritsOnlyItsEndOfTheSocket
the mount helper inherited socket 4
    mount_helper_test.go:127: fusermount: running .../fuse.test: exit status 1
--- FAIL: TestMountHelperInheritsOnlyItsEndOfTheSocket (0.02s)

With this PR, both tests pass, also under -race. Each test fails without its own change: with the CloseOnExec calls removed, only the second test fails; with the close deferred again, only the first test hangs.

No test pins the reap. I checked it once with a throwaway test that lists the test process's children with ps after fusermount returns with wait false. On master the helper stayed a zombie (Z) for the 5 seconds the check waited. With this PR it was gone.

Validation

CI runs no go test, so these local runs are the test evidence.

  • macOS 27.2, arm64, Go 1.27.3, and Ubuntu 26.04, Linux 7.0, x86_64, Go 1.26.5: both tests, before and after this PR, with the results above.
  • gofmt -l . prints nothing.
  • go build ./... passes with GOOS=linux and with GOOS=darwin.
  • go vet ./... reports the same findings as on master, with GOOS=linux and with GOOS=darwin, all in files this PR does not touch: unkeyed fusekernel.Protocol literals, reflect.SliceHeader uses and, on linux/arm64, syscall.SYS_DUP2 in samples/flushfs.

Not changed

  • With wait false, fusermount still ignores the helper's exit status, and Mount does not wait for the helper's result. Reporting it would change when Mount returns on macOS, which I cannot check without running mount_macfuse.
  • fusermount still closes its end of the socket once it has read the device.

fusermount kept its own copy of the helper's end of the socket pair open
until it returned. A helper that exited without passing a device left
ReadMsgUnix waiting for a peer that this process held itself, so Mount
hung forever.

- fusermount closes its copy of the helper's end once the helper has
  started. The read then fails with EOF when the helper exits without
  passing a device.
- The socket pair is created close-on-exec under syscall.ForkLock. The
  helper inherits only its end, as fd 3, and a child that another goroutine
  forks meanwhile inherits neither end.
- With wait false, fusermount reaps the helper in the background once it
  exits. It used to stay a zombie.
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.

1 participant