Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My reproduction program for https://github.com/golang/go/issues/10886
package main
import (
"database/sql"
"fmt"
_ "github.com/VividCortex/mysql"
"net/http"
_ "net/http/pprof"
"time"
)
const numConnToOpen = 5
func main() {
startTime := time.Now()
defer func() {
fmt.Printf("Exiting after %vs\n", time.Now().Sub(startTime).Seconds())
}()
go func() {
fmt.Println(http.ListenAndServe(":6060", nil))
}()
db, err := sql.Open("mysql", "root:password@tcp(1.2.3.4:3306)/mysql?timeout=2s")
if err != nil {
fmt.Println(err)
}
db.SetMaxOpenConns(2)
db.SetMaxIdleConns(0)
done := make(chan bool, numConnToOpen)
for i := 0; i < numConnToOpen; i++ {
go func() {
err := db.Ping()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Done in %vs\n", time.Now().Sub(startTime).Seconds())
done <- true
}()
}
for i := 0; i < numConnToOpen; i++ {
<-done
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment