fix: potential context leak

This commit is contained in:
Muyao CHEN 2024-10-03 23:41:39 +02:00
parent 3d5212fb53
commit c22b5d2372

View File

@ -19,7 +19,8 @@ func OpenDB(dsn string) (*sql.DB, error) {
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
err = db.PingContext(ctx)
if err != nil {
fmt.Println(err)