Skip to content

Commit

Permalink
Fix IdlePool option (#380)
Browse files Browse the repository at this point in the history
The zero value was not the same as in the stdlib and could cause
perfs issues. This will now not call SetMaxIdleConns when IdlePool
is set to the zero value.

Fixes #376
  • Loading branch information
stanislas-m committed May 5, 2019
1 parent cbfa004 commit 2e56ce4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func (c *Connection) Open() error {
return errors.Wrap(err, "could not open database connection")
}
db.SetMaxOpenConns(details.Pool)
db.SetMaxIdleConns(details.IdlePool)
if details.IdlePool != 0 {
db.SetMaxIdleConns(details.IdlePool)
}
c.Store = &dB{db}

if d, ok := c.Dialect.(afterOpenable); ok {
Expand Down
2 changes: 1 addition & 1 deletion connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ConnectionDetails struct {
URL string
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetMaxOpenConns
Pool int
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns
// Defaults to 2. See https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns
IdlePool int
Options map[string]string
// Query string encoded options from URL. Example: "sslmode=disable"
Expand Down

0 comments on commit 2e56ce4

Please sign in to comment.