Repository navigation
Conversation
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.
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.
Summary
fusermountstarts 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 inReadMsgUnix(L196) never sees EOF, because this process still holds the other end.Mounthangs forever.waitfalse, 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, hangsMount.waittrue, as forfusermount3on Linux (mount_linux.go L153),cmd.Runreturns a nonzero exit status as an error before the read. Only a helper that exits with status 0 without passing a device hangsMount.This PR changes
fusermount:fusermountfail atReadMsgUnixwith EOF.syscall.ForkLock, as thenetpackage creates sockets on darwin (sysSocketinnet/sys_cloexec.go).syscall.Socketpairreturns 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.Cmdstill passes the helper its end as fd 3.waitfalse, nothing waited for the helper, so it stayed a zombie for the life of the process, one per mount.fusermountnow reaps it in a background goroutine.I have not run this against
mount_macfuseorfusermount3. 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:
TestFakeMountHelperacts as one whenFUSE_TEST_FAKE_MOUNT_HELPERis set, and skips otherwise. Run them with:TestFusermountFailsWhenTheHelperPassesNoDevice, withwaittrue and false: the helper exits with status 0 without passing a device.fusermountmust fail atReadMsgUnixwith 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/nullback as the device.fusermountruns it withwaittrue 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 inReadMsgUnixuntilgo test -timeoutends it (excerpt, paths shortened):On master, the helper of the second test inherits a socket of the pair:
With this PR, both tests pass, also under
-race. Each test fails without its own change: with theCloseOnExeccalls 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
psafterfusermountreturns withwaitfalse. 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.gofmt -l .prints nothing.go build ./...passes withGOOS=linuxand withGOOS=darwin.go vet ./...reports the same findings as on master, withGOOS=linuxand withGOOS=darwin, all in files this PR does not touch: unkeyedfusekernel.Protocolliterals,reflect.SliceHeaderuses and, on linux/arm64,syscall.SYS_DUP2insamples/flushfs.Not changed
waitfalse,fusermountstill ignores the helper's exit status, andMountdoes not wait for the helper's result. Reporting it would change whenMountreturns on macOS, which I cannot check without runningmount_macfuse.fusermountstill closes its end of the socket once it has read the device.