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

return an error instead of panic in case of panic: runtime error #39265

Closed
smallnest opened this issue May 27, 2020 · 1 comment
Closed

return an error instead of panic in case of panic: runtime error #39265

smallnest opened this issue May 27, 2020 · 1 comment

Comments

@smallnest
Copy link

smallnest commented May 27, 2020

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

$ go version
compile environment:

go version go1.14.2 darwin/amd64

running environment:

CentOS Linux release 7.3.1611 (Core)/3.10.0/x64

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
GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/abc/Library/Caches/go-build"
GOENV="/Users/abc/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOOS="darwin"
GOPATH="/Users/abc/go"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gq/jd9v5dd95p570hkztblb8ht40000gn/T/go-build162051472=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

We have a redis proxy services, deployed in two servers. They receive responses from clients and redirect other redis services.

What did you expect to see?

The two run well.

What did you see instead?

The two services are crash at 18:17 and the stack is :

panic: runtime error: slice bounds out of range [:81] with capacity 72

goroutine 2382138 [running]:
internal/poll.(*FD).Write(0xc025650e80, 0xc0f7054230, 0x51, 0x48, 0x0, 0x0, 0x0)
        /usr/local/go/src/internal/poll/fd_unix.go:268 +0x405
net.(*netFD).Write(0xc025650e80, 0xc0f7054230, 0x51, 0x48, 0x3c, 0x0, 0x0)
        /usr/local/go/src/net/fd_unix.go:220 +0x4f
net.(*conn).Write(0xc07798ea28, 0xc0f7054230, 0x51, 0x48, 0x0, 0x0, 0x0)
        /usr/local/go/src/net/net.go:196 +0x8e
git.abc.com/redisproxy/proxy/doublewriter.(*Worker).start(0xc0006accc0)
        /Users/abc/go/src/git.abc.com/redisproxy/proxy/doublewriter/writer.go:169 +0x156
created by git.abc.com/redisproxy/proxy/doublewriter.(*Writer).AddWorker
        /Users/abc/go/src/git.abc.com/redisproxy/proxy/doublewriter/writer.go:80 +0x29f

Problem

I searched issues and found some similar isssues: #22522 #22102 . According to descriptions of those issues, it looks it is OS issue/driver issue. When go call the write syscall.Write, the syscall returns bigger number than input, which caused the panic.

So is it a better solution to check the slice range
at https://github.com/golang/go/blob/master/src/internal/poll/fd_unix.go#L267 and returns an error if overflow?

@randall77
Copy link
Contributor

The slices passed to these functions look bad. Their length is 0x51 but their capacity is only 0x48.
You might want to check where git.abc.com/redisproxy/proxy/doublewriter.(*Worker).start gets its slice from. Particularly, check any uses of unsafe or cgo - you should not be able to construct such a slice with pure Go. Also run with the race detector, as a data race could cause this as well.

Closing, as this does not appear to be a bug in Go (yet). Please reopen if you find more evidence pointing to Go itself.

I don't think this issue is related to #22522 or #22102 at all. They have input slices with valid len/cap.

@golang golang locked and limited conversation to collaborators May 27, 2021
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