Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ClydeByrdIII opened this issue Apr 3, 2024 · 1 comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ClydeByrdIII
Copy link

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

@ClydeByrdIII ClydeByrdIII changed the title os: missing conversion of internal/poll.ErrFileClosing to fs.ErrClosed in os.Stat() os: missing conversion of internal/poll.ErrFileClosing to fs.ErrClosed in os.File.Stat() Apr 3, 2024
@gopherbot
Copy link

Change https://go.dev/cl/576119 mentions this issue: os: convert poll.ErrFileClosed to ErrClosed for Stat

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 3, 2024
@dmitshur dmitshur added this to the Go1.23 milestone Apr 3, 2024
@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants