aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/sql.go
diff options
context:
space:
mode:
authorShinnosuke Sawada <6warashi9@gmail.com>2020-08-17 20:37:51 +0900
committerDaniel Theophanes <kardianos@gmail.com>2020-08-29 09:20:35 +0000
commit4fc3896e7933e31822caa50e024d4e139befc75f (patch)
tree614d5460b8a3653159d156653ff042572d8e2d1e /src/database/sql/sql.go
parent27a30186abc18a8fc22b8ab40e3ee9f29d81c1d4 (diff)
downloadgo-4fc3896e7933e31822caa50e024d4e139befc75f.tar.xz
database/sql: shortestIdleTimeLocked correct min comparison
When zero or less, maxIdleTime and maxLifetime means unlimited. Helper function shortestIdleTimeLocked must not return the minimum of the two until both are verified to be greater then zero. Fixes #40841 Change-Id: I1130332baf4ad259cd90c10f4221f5def8510655 Reviewed-on: https://go-review.googlesource.com/c/go/+/248817 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Diffstat (limited to 'src/database/sql/sql.go')
-rw-r--r--src/database/sql/sql.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 0b85db66b9..e3580698fd 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -869,6 +869,13 @@ func (db *DB) maxIdleConnsLocked() int {
}
func (db *DB) shortestIdleTimeLocked() time.Duration {
+ if db.maxIdleTime <= 0 {
+ return db.maxLifetime
+ }
+ if db.maxLifetime <= 0 {
+ return db.maxIdleTime
+ }
+
min := db.maxIdleTime
if min > db.maxLifetime {
min = db.maxLifetime