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

get poll.ErrFileClosing on syscall.RawConn #29828

Closed
cpuguy83 opened this issue Jan 19, 2019 · 3 comments
Closed

get poll.ErrFileClosing on syscall.RawConn #29828

cpuguy83 opened this issue Jan 19, 2019 · 3 comments

Comments

@cpuguy83
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12beta2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build455574136=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://github.com/containerd/fifo/compare/master...cpuguy83:add_raw_copy?expand=1

Using the Read method on a syscall.RawConn (from *os.File, which is created from *os.NewFile()), I'm getting an error returned: internal/poll.ErrFileClosing from Read()

This is happening when the file gets closed while a read is in progress.

What did you expect to see?

I would not really expect any error here in this case other than io.EOF, perhaps.

What did you see instead?

An error which cannot be handled except from go itself: internal/poll.ErrFileClosing

--- FAIL: TestRawCopy (0.00s)
    raw_linux_test.go:67:
        	Error Trace:	raw_linux_test.go:67
        	Error:      	Received unexpected error:
        	            	use of closed file
        	            	read error
        	            	github.com/containerd/fifo.rawCopy
        	            		/go/src/github.com/containerd/fifo/raw_linux.go:133
        	            	github.com/containerd/fifo.(*fifo).rawWriteTo
        	            		/go/src/github.com/containerd/fifo/raw_linux.go:106
        	            	github.com/containerd/fifo.(*fifo).WriteTo
        	            		/go/src/github.com/containerd/fifo/raw_linux.go:31
        	            	io.copyBuffer
        	            		/usr/local/go/src/io/io.go:384
        	            	io.Copy
        	            		/usr/local/go/src/io/io.go:364
        	            	github.com/containerd/fifo.TestRawCopy.func1
        	            		/go/src/github.com/containerd/fifo/raw_linux_test.go:39
        	            	runtime.goexit
        	            		/usr/local/go/src/runtime/asm_amd64.s:1337
        	            	error in copy, copied 12 bytes
        	            	github.com/containerd/fifo.TestRawCopy.func1
        	            		/go/src/github.com/containerd/fifo/raw_linux_test.go:40
        	            	runtime.goexit
        	            		/usr/local/go/src/runtime/asm_amd64.s:1337
        	Test:       	TestRawCopy

I'm probably doing something wrong or silly, especially at 5 o'clock on a Friday but in any case it seems like like a bug to get an error from internal/*

@ianlancetaylor
Copy link
Contributor

I'm not sure quite what to say except that yes, that is how it works, and that is how it has worked for years, for better or for worse. I'm going to close this as a dup of #4373, but please feel free to comment if you disagree.

@cpuguy83
Copy link
Author

@ianlancetaylor Is there no way to resolve this even though syscall.Conn is a new interface for *os.File in go1.12?

@ianlancetaylor
Copy link
Contributor

This isn't new to using syscall.Conn. You can see the same thing if you Read from a pipe and close the pipe in a different goroutine. The only reason you don't see it with a file is that reading from a file normally doesn't block, but if you are very careful with timing you can see it with a file too.

The whole situation is unfortunate and you can read #4373 to see why. Until that issue is resolved I suggest that you do what most programs do and write strings.Contains(err.Error(), "use of closed file").

@golang golang locked and limited conversation to collaborators Jan 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants