fix: segfault on database connection failure
This commit is contained in:
parent
fe84f97f18
commit
c7538a98e5
@ -40,17 +40,22 @@ func newWebCmd() *cobra.Command {
|
|||||||
)
|
)
|
||||||
var db *sqlx.DB
|
var db *sqlx.DB
|
||||||
var err error
|
var err error
|
||||||
retryNumber := 0
|
var retryDuration time.Duration
|
||||||
for i := 0; retryNumber <= 3; i++ {
|
maxRetryNumber := 4
|
||||||
retryNumber++
|
for i := 0; i < maxRetryNumber; i++ {
|
||||||
db, err = sqlx.Connect("postgres", connection)
|
db, err = sqlx.Connect("postgres", connection)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
retryDuration := time.Duration(i*2) * time.Second
|
retryDuration = time.Duration(i*2) * time.Second
|
||||||
log.WithFields(log.Fields{"retryNumber": retryNumber, "retryDuration": retryDuration}).WithError(err).Error("issue connecting to database, retrying")
|
log.WithFields(log.Fields{"retryNumber": i, "retryDuration": retryDuration}).WithError(err).Error("issue connecting to database, retrying")
|
||||||
|
if i != maxRetryNumber-1 {
|
||||||
time.Sleep(retryDuration)
|
time.Sleep(retryDuration)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
db.SetMaxOpenConns(25)
|
db.SetMaxOpenConns(25)
|
||||||
db.SetMaxIdleConns(25)
|
db.SetMaxIdleConns(25)
|
||||||
db.SetConnMaxLifetime(5 * time.Minute)
|
db.SetConnMaxLifetime(5 * time.Minute)
|
||||||
|
Loading…
Reference in New Issue
Block a user