Skip to content

os: missing conversion of internal/poll.ErrFileClosing to fs.ErrClosed in os.File.Stat() #66665

@ClydeByrdIII

Description

@ClydeByrdIII

Go version

go 1.21.8 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY=''
GOROOT='/home/user/go/v1.21.8'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/user/go/v1.21.8/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.8'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK='/home/user/project/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3303884229=/tmp/go-build -gno-record-gcc-switches'

What did you do?

The following program tries to catch an os.ErrClosed error
https://go.dev/play/p/3fsVnPZCdo5

// You can edit this code!
// Click here and start typing.
package main

import (
	"errors"
	"fmt"
	"os"
	"reflect"
)

func main() {
	closed, err := os.Open("/dev/null")
	if err != nil {
		panic(fmt.Sprintf("os.Open(/dev/null) = %v", err))
	}
	closed.Close()
	if _, err := closed.Stat(); err != nil {

		if errors.Is(err, os.ErrClosed) {
			fmt.Println("File already closed")
		} else {
			fmt.Printf("type: '%s', value '%v'", reflect.TypeOf(err), err)
		}
	}
}

What did you see happen?

The PathError returned is not recognized as an os.ErrClosed and wraps an internal error internal/poll.ErrFileClosing

type: '*fs.PathError', value 'stat /dev/null: use of closed file'

What did you expect to see?

I expected a Stat() on a closed file would return os.ErrClosed / fs.ErrClosed


I think this might be similar to #58622; I'm trying to catch File closed errors from fileObj.Stat() and I can't import
internal/poll.ErrFileClosing

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions