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>
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 0b85db6..e358069 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -869,6 +869,13 @@
}
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