Open HoangTheQuyen opened 1 year ago
package main
import (
"database/sql"
"log"
"time"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
func connect(dsn string) *gorm.DB {
logMode := logger.Silent
sqlDB, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatalf("Error opening database: %v", err)
}
err = sqlDB.Ping()
if err != nil {
log.Fatalf("Error pinging database: %v", err)
}
// Reduce connection max lifetime to handle potential proxy/connection aging
sqlDB.SetConnMaxLifetime(2 * time.Minute)
sqlDB.SetMaxIdleConns(10)
sqlDB.SetMaxOpenConns(50)
gormDB, err := gorm.Open(mysql.New(mysql.Config{Conn: sqlDB}), &gorm.Config{
Logger: logger.Default.LogMode(logMode),
})
if err != nil {
log.Fatalf("Error opening GORM database: %v", err)
}
return gormDB
}
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
maxconn 20480
ulimit-n 65536
defaults
log global
mode tcp
option tcplog
option dontlognull
timeout connect 10s
timeout client 3h
timeout server 3h
listen tidbcluster
bind *:4000
balance leastconn
option tcp-check
timeout client 3h
timeout server 3h
maxconn 20000
server tidb49101 10.11.23.100:4000 check inter 10s rise 2 fall 3
server tidb49102 10.11.23.101:4000 check inter 10s rise 2 fall 3
server tidb49103 10.11.23.102:4000 check inter 10s rise 2 fall 3
General Question
I have a few questions about bugs when i using ha-proxy + tiadb with golang to connect to Invalid connection using GORM has anyone seen it yet? Please helm me, tks all Bro Info : Go 1.18 gorm.io/driver/mysql v1.4.3 gorm.io/gorm v1.24.1 Currently wait_timeout configuration is 28800s(8h). Source golang to connecting to