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

Printf "database/sql" got panic under high qps pressure. #27507

Closed
Exlsunshine opened this issue Sep 5, 2018 · 3 comments
Closed

Printf "database/sql" got panic under high qps pressure. #27507

Exlsunshine opened this issue Sep 5, 2018 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@Exlsunshine
Copy link

Exlsunshine commented Sep 5, 2018

Please answer these questions before submitting your issue. Thanks!
The following package is not thread safe: "database/sql"

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

go version go1.7 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/data/home/markgyang/project/video-content-platform/spcdp_cp"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build491876654=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"

What did you do?

I imported this package "database/sql", and got a object: db *sql.DB
Then I initialized it and printed it: fmt.Printf("%v", db)

What did you expect to see?

Print db structure as usual.

What did you see instead?

It printed the db structure as normal, but as long as I increased the frequency of calling fmt.Printf("%v", db), I got golang concurrent map read and map write error, then the program panic during runtime.

@davecheney
Copy link
Contributor

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

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 5, 2018
@kardianos
Copy link
Contributor

The sql.DB contains several maps which should only be read or written to under locks.

Calling fmt.Printf("%v", &sql.DB{}) will attempt to read these map structures. This will cause a race condition the runtime can (and did) detect for you.

  1. Don't do this.
  2. What are you trying to do by printing out the sql.DB? Are you trying to get stats? Stats has been expanded greatly in Go1.11.

@Exlsunshine
Copy link
Author

The sql.DB contains several maps which should only be read or written to under locks.

Calling fmt.Printf("%v", &sql.DB{}) will attempt to read these map structures. This will cause a race condition the runtime can (and did) detect for you.

  1. Don't do this.
  2. What are you trying to do by printing out the sql.DB? Are you trying to get stats? Stats has been expanded greatly in Go1.11.

Thanks for the reply.
I want to print out the db because I want to identify which database I am currently working on.

@golang golang locked and limited conversation to collaborators Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants