Skip to content

Instantly share code, notes, and snippets.

@methane

methane/t.go Secret

Last active November 30, 2018 13:05
Show Gist options
  • Save methane/2d3ea01bfa88bfa275514146791817db to your computer and use it in GitHub Desktop.
Save methane/2d3ea01bfa88bfa275514146791817db to your computer and use it in GitHub Desktop.
package main
import (
"context"
"database/sql"
_ "github.com/go-sql-driver/mysql"
"log"
"sync"
"time"
)
func main() {
db, _ := sql.Open("mysql", "root@tcp(127.0.0.1:3306)/")
var waitTimeout int
err := db.QueryRow("SELECT @@wait_timeout").Scan(&waitTimeout)
if err != nil {
panic(err)
}
log.Printf("wait_timeout=%v", waitTimeout)
var wg sync.WaitGroup
for i := 60; i < 3600; i += 30 {
c, err := db.Conn(context.Background())
if err != nil {
log.Print(err)
break
}
wg.Add(1)
go func(c *sql.Conn, n int) {
time.Sleep(time.Second * time.Duration(n))
_, err := c.ExecContext(context.Background(), "SELECT 42")
log.Printf("%v - %v", n, err)
c.Close()
wg.Done()
}(c, i)
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment