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

File descriptor slice bounds out of range error #30330

Closed
fharding1 opened this issue Feb 20, 2019 · 5 comments
Closed

File descriptor slice bounds out of range error #30330

fharding1 opened this issue Feb 20, 2019 · 5 comments

Comments

@fharding1
Copy link

fharding1 commented Feb 20, 2019

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

$ go version
go version go1.11.5 linux/amd64

Does this issue reproduce with the latest release?

Yes, I'm running the latest release.

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

go env Output
$ go env
GOARCH="amd64"
GOBIN="/home/franklin/go/bin"
GOCACHE="/home/franklin/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/franklin/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-build509731769=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Wrote a program that fires off one HTTP request and writes one file for each of ~200,000 entries.

What did you expect to see?

I expected to be able to write a JSON blob to a file with ioutil.WriteFile.

What did you see instead?

After about 100,000 entries (so 100k HTTP requests and 100k written files), I got a panic. I wasn't out of storage or file descriptors. This was running on an XFS filesystem. I wish I could reproduce this but after running the program again I am unable to, and I can't share the source here.

panic: runtime error: slice bounds out of range

goroutine 103762 [running]:
internal/poll.(*FD).Write(0xc0142e9620, 0xc00e00f201, 0xfffffffffffffffe, 0x1ff, 0x0, 0x0, 0x0)
	/usr/local/go/src/internal/poll/fd_unix.go:268 +0x37b
os.(*File).write(0xc00008f550, 0xc00e00f201, 0xfffffffffffffffe, 0x1ff, 0x0, 0xc0006d9cd8, 0x4ad6ff)
	/usr/local/go/src/os/file_unix.go:266 +0x4e
os.(*File).Write(0xc00008f550, 0xc00e00f201, 0xfffffffffffffffe, 0x1ff, 0xc00008f550, 0x0, 0x0)
	/usr/local/go/src/os/file.go:145 +0x6f
io/ioutil.WriteFile(0xc032b0a960, 0x27, 0xc00e00f201, 0xfffffffffffffffe, 0x1ff, 0xc0000001ff, 0x27, 0x0)
	/usr/local/go/src/io/ioutil/ioutil.go:84 +0x94
main.main.func2(0xc000780780, 0xc000ad56f0, 0xc000ad56e0, 0x96b6, 0x5a600)
	/home/franklin/REDACTED/main.go:104 +0x4d1
created by main.main
	/home/franklin/REDACTED/main.go:77 +0x36f
@ianlancetaylor
Copy link
Contributor

Something is wrong with the slice passed to ioutil.WriteFile. The stack trace shows that the slice has length -2 (and capacity 511). This looks like a bug or race condition in your program, or since it only happened once it could perhaps be a hardware error. There should be no normal way to get a slice of length -2.

@fharding1
Copy link
Author

@ianlancetaylor thanks for the response and for catching that, I should have tried harder to decode the stack trace myself. That's really strange, since I'm not doing anything out of the ordinary to get the byte slice I pass to ioutil.WriteFile.

jsonp, err := ioutil.ReadAll(redactedResponse.Body)
if err != nil {
	log.Println(errors.Wrap(err, "redacted"), redacted)
	return
}

jsonp = jsonp[1 : len(jsonp)-1] // remove the JSONP call stuff

err = ioutil.WriteFile(fmt.Sprintf(redacted, redacted, redacted), jsonp, 0777)

That jsonp = line could panic if the length was less than 2, but it wasn't that line that panicked.

@ianlancetaylor
Copy link
Contributor

Thanks. I don't have an explanation. I recommend 1) run your program under the race detector; 2) see if this problem happens again.

@fharding1
Copy link
Author

Will do, thanks a lot. I'll call this a hardware issue and close the issue for now, and reopen if I can reproduce with the race detector.

@fharding1
Copy link
Author

FWIW there were no data races and I wasn't able to reproduce it 🤷‍♂️. Weird.

@golang golang locked and limited conversation to collaborators Feb 20, 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