From 87d4170730ead02ae82105da6195dc30c6248dfc Mon Sep 17 00:00:00 2001 From: David Sanchez <64162682+dsfaccini@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:27:23 -0500 Subject: [PATCH] Treat an ECONNABORTED read from /dev/fuse as EOF on Linux 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. --- connection.go | 16 +++++++++++- connection_linux_test.go | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 connection_linux_test.go diff --git a/connection.go b/connection.go index 429a3b7c..e154fe51 100644 --- a/connection.go +++ b/connection.go @@ -383,6 +383,10 @@ func (c *Connection) handleInterrupt(fuseID uint64) { cancel() } +// initInMessage is (*buffer.InMessage).Init. Tests replace it to make a read +// from the device fail. +var initInMessage = (*buffer.InMessage).Init + // Read the next message from the kernel. The message must later be destroyed // using destroyInMessage. func (c *Connection) readMessage() (*buffer.InMessage, error) { @@ -392,12 +396,17 @@ func (c *Connection) readMessage() (*buffer.InMessage, error) { // Loop past transient errors. for { // Attempt a read. - err := m.Init(c.dev) + err := initInMessage(m, c.dev) // Special cases: // // * ENODEV means fuse has hung up. // + // * On Linux, ECONNABORTED does too. fuse_dev_do_read returns it when + // the connection is aborted, as an unmount does, after the read + // took a request off the pending list + // (https://github.com/torvalds/linux/blob/v6.12/fs/fuse/dev.c#L1332-L1340). + // // * EINTR means we should try again. (This seems to happen often on // OS X, cf. http://golang.org/issue/11180) // @@ -406,6 +415,11 @@ func (c *Connection) readMessage() (*buffer.InMessage, error) { case syscall.ENODEV: err = io.EOF + case syscall.ECONNABORTED: + if runtime.GOOS == "linux" { + err = io.EOF + } + case syscall.EINTR: err = nil continue diff --git a/connection_linux_test.go b/connection_linux_test.go new file mode 100644 index 00000000..54e07ea5 --- /dev/null +++ b/connection_linux_test.go @@ -0,0 +1,56 @@ +// Copyright 2026 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package fuse + +import ( + "io" + "os" + "syscall" + "testing" + + "github.com/jacobsa/fuse/internal/buffer" +) + +// fuse_dev_do_read fails with ECONNABORTED when the connection is aborted +// after the read took a request off the pending list. An unmount aborts the +// connection. +func TestReadOpReturnsEOFWhenTheReadIsAborted(t *testing.T) { + tests := []struct { + name string + errno syscall.Errno + wantEOF bool + }{ + {"ENODEV", syscall.ENODEV, true}, + {"ECONNABORTED", syscall.ECONNABORTED, true}, + {"EIO", syscall.EIO, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var readErr error = &os.PathError{Op: "read", Path: "/dev/fuse", Err: tt.errno} + oldInit := initInMessage + initInMessage = func(*buffer.InMessage, io.Reader) error { return readErr } + t.Cleanup(func() { initInMessage = oldInit }) + + c := &Connection{inMessageBufSize: buffer.GetPageSize()} + _, _, err := c.ReadOp() + if tt.wantEOF && err != io.EOF { + t.Errorf("ReadOp = %v, want io.EOF", err) + } + if !tt.wantEOF && err != readErr { + t.Errorf("ReadOp = %v, want %v", err, readErr) + } + }) + } +}