Skip to content

Treat an ECONNABORTED read from /dev/fuse as EOF on Linux - #207

Open
dsfaccini wants to merge 1 commit into
jacobsa:masterfrom
dsfaccini:upstream/econnaborted-eof
Open

dsfaccini wants to merge 1 commit into
jacobsa:masterfrom
dsfaccini:upstream/econnaborted-eof

Conversation

@dsfaccini

Copy link
Copy Markdown

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

Summary

On Linux, a read from /dev/fuse can fail with ECONNABORTED while the file system is unmounted. readMessage maps only ENODEV to io.EOF (connection.go L388-L423), so ReadOp returns the error. fuseutil's ServeOps panics on every ReadOp error other than io.EOF (fuseutil/file_system.go L107-L115), so the process crashes at unmount.

This PR makes readMessage map ECONNABORTED to io.EOF on Linux, as it does ENODEV.

I hit the panic in samples/forgetfs (ForgetFSTest.Open_ManyTimes) while running the mounting tests on a GitHub Actions Ubuntu runner. It came from fileSystemServer.ServeOps:

panic: read /dev/fuse: software caused connection abort

When the read returns ECONNABORTED

fuse_dev_do_read takes a request off the pending list (dev.c L1315-L1318). It then checks the connection again under fpq->lock. When the connection was aborted in between, it ends the request and returns ECONNABORTED (L1332-L1340). fuse_abort_conn clears fpq->connected (L2261) before fiq->connected (L2285), so a read that got past the fiq->connected check can land there. Unmounting aborts the connection (fuse_conn_destroy, inode.c L1946-L1953).

The other two abort checks in fuse_dev_do_read return ECONNABORTED only when the connection was aborted through /sys/fs/fuse/connections/<N>/abort after the file system negotiated FUSE_ABORT_ERROR (dev.c L1296-L1299, L1352-L1355, control.c L34-L41). They return ENODEV otherwise. This library does not request FUSE_ABORT_ERROR.

The mapping is Linux-only, because the code above is where the errno comes from. On macOS readMessage behaves as before.

Tests

TestReadOpReturnsEOFWhenTheReadIsAborted (connection_linux_test.go) makes the read fail with an *os.PathError holding ENODEV, ECONNABORTED or EIO, the form os.File.Read returns. ReadOp must return io.EOF for the first two and the error itself for EIO. The test does not mount. Run it with:

go test -run '^TestReadOpReturnsEOFWhenTheReadIsAborted$' .

A test cannot make a read from a real file fail with ECONNABORTED, so readMessage now calls (*buffer.InMessage).Init through a package variable, initInMessage, which the test replaces. If you prefer no test seam, I can drop the variable and the test.

On master (a124548) with only initInMessage added, the ECONNABORTED case fails:

=== RUN   TestReadOpReturnsEOFWhenTheReadIsAborted
=== RUN   TestReadOpReturnsEOFWhenTheReadIsAborted/ENODEV
=== RUN   TestReadOpReturnsEOFWhenTheReadIsAborted/ECONNABORTED
    connection_linux_test.go:49: ReadOp = read /dev/fuse: software caused connection abort, want io.EOF
=== RUN   TestReadOpReturnsEOFWhenTheReadIsAborted/EIO
--- FAIL: TestReadOpReturnsEOFWhenTheReadIsAborted (0.00s)
    --- PASS: TestReadOpReturnsEOFWhenTheReadIsAborted/ENODEV (0.00s)
    --- FAIL: TestReadOpReturnsEOFWhenTheReadIsAborted/ECONNABORTED (0.00s)
    --- PASS: TestReadOpReturnsEOFWhenTheReadIsAborted/EIO (0.00s)
FAIL

With this PR, all three cases pass, also under -race.

Validation

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

  • Ubuntu 26.04, Linux 7.0, x86_64, Go 1.26.5: the test above, before and after this PR. The test file is Linux-only.
  • 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

  • An ECONNABORTED read on macOS stays an error.

fuse_dev_do_read returns ECONNABORTED when the connection is aborted, as an
unmount does, after the read took a request off the pending list. readMessage
mapped only ENODEV to io.EOF, so ReadOp returned the error and
fuseutil's ServeOps panicked on it at unmount.

readMessage now maps ECONNABORTED to io.EOF on Linux. A test replaces the
read through the new initInMessage variable.
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