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

database/sql.(*DB).conn: slice bounds out of range [:824640893215] with capacity 0 #41938

Open
juliusmh opened this issue Oct 12, 2020 · 2 comments
Open

Comments

@juliusmh
Copy link

@juliusmh juliusmh commented Oct 12, 2020

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

$ go version
go version go1.15 linux/amd64

Does this issue reproduce with the latest release?

The problem occurs only sometimes, so reproducing is hard. The error happens on the latest released version.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xyz/.cache/go-build"
GOENV="/home//xyz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home//xyz/go/pkg/mod"
GONOPROXY="github.com/xyz"
GONOSUMDB="github.com/xyz"
GOOS="linux"
GOPATH="/home/juliusmh/go/"
GOPRIVATE="github.com/grid-x"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
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-build786391877=/tmp/go-build -gno-record-gcc-switches"

What did you do?

We're using sql/database.DB.PingContext(...) to check connectivity status to a postgres database in a handler, which is invoked in a goroutine. Sometimes the call crashes with an error that is beyond my understanding.

// It's standard use I would guess:
// db is of type *sql.DB
// we're connected to a postgres DB using sqlx, we use "github.com/lib/pq"
db.SetMaxOpenConns(30)
db.SetMaxIdleConns(15)
db.SetConnMaxLifetime(30*time.Minute)
db.SetConnMaxIdleTime(5*time.Minute)
go func(){
    ctx, cancel := context.WithTimeout(context.Background, 4*time.Second)
    err := db.PingContext(ctx)
    cancel()
    if err != nil { ... }
}

What did you expect to see?

I want to either receive an error, or nil. Got panic instead.

What did you see instead?

10:34:30.092 panic: runtime error: slice bounds out of range [:824640893215] with capacity 0
10:34:30.092 goroutine 152927555 [running]:
10:34:30.092 database/sql.(*DB).conn(0xc00000eb08, 0x1b856e0, 0xc00111b680, 0x1, 0x261b140, 0x0, 0xc000e93ea8)
10:34:30.092 	/usr/local/go/src/database/sql/sql.go:1209 +0xfb2
10:34:30.092 database/sql.(*DB).PingContext(0xc00000eb08, 0x1b856e0, 0xc00111b680, 0x0, 0xc001cc237f)
10:34:30.092 	/usr/local/go/src/database/sql/sql.go:799 +0x90
10:34:30.092 github.com/xyz/foo/pkg/bar.(*FooBar).Status(0xc0007c75f0, 0x1b856e0, 0xc00111b680, 0x100000001, 0x0, 0xc00008a060, 0x0)
@davecheney
Copy link
Contributor

@davecheney davecheney commented Oct 12, 2020

This could be memory corruption. Have you tried running your program under the race detector? See https://blog.golang.org/race-detector .

@juliusmh
Copy link
Author

@juliusmh juliusmh commented Oct 13, 2020

Quick follow up @davecheney: I started the program with -race flag (as described here) and spammed the handler with thousands of requests. I did not receive any warnings/errors nor was it possible to reproduce the bug. I then tried dirty restarting the database, tried different versions of postgres with no success.

Might this be the rare case of a random bit flip?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants