Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Set timeouts on rawSQL before gorm (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Nov 20, 2020
1 parent 4986687 commit 69a0bec
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (db *Database) OpenWithCacher(ctx context.Context, cacher cache.Cacher) err
return fmt.Errorf("failed to create database connection")
}

// Set connection configuration.
rawSQL.SetConnMaxLifetime(c.MaxConnectionLifetime)
rawSQL.SetConnMaxIdleTime(c.MaxConnectionIdleTime)

var rawDB *gorm.DB
if err := withRetries(ctx, func(ctx context.Context) error {
var err error
Expand All @@ -178,10 +182,6 @@ func (db *Database) OpenWithCacher(ctx context.Context, cacher cache.Cacher) err
return fmt.Errorf("failed to initialize gorm")
}

// Set connection configuration.
rawDB.DB().SetConnMaxLifetime(c.MaxConnectionLifetime)
rawDB.DB().SetConnMaxIdleTime(c.MaxConnectionIdleTime)

// Log SQL statements in debug mode.
if c.Debug {
rawDB = rawDB.LogMode(true)
Expand Down

0 comments on commit 69a0bec

Please sign in to comment.