Skip to content

Commit

Permalink
✨ feat: added context timeout while trying to connect mysql #6
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Oct 4, 2023
1 parent 4029f67 commit 8a203c7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mysqlconn/mysqlconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func NewClient(config mysql.MysqlConfig) (*MySql, dbx.Dbx) {
client.SetMaxOpenConns(config.MaxOpenConn)
client.SetMaxIdleConns(config.MaxIdleConn)
client.SetConnMaxLifetime(time.Duration(time.Duration(config.MaxLifeTimeMinutesConn).Minutes()))
err = client.PingContext(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), config.Timeout)
defer cancel()
err = client.PingContext(ctx)
if err != nil {
s.SetConnected(false).SetError(err).SetMessage(err.Error())
return &MySql{}, *s
Expand Down

0 comments on commit 8a203c7

Please sign in to comment.