]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: shortestIdleTimeLocked correct min comparison
authorShinnosuke Sawada <6warashi9@gmail.com>
Mon, 17 Aug 2020 11:37:51 +0000 (20:37 +0900)
committerDaniel Theophanes <kardianos@gmail.com>
Sat, 29 Aug 2020 09:20:35 +0000 (09:20 +0000)
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>
src/database/sql/sql.go

index 0b85db66b9a2dc88d339cf05d1157bde0dc055c7..e3580698fd6fa48ba7b508889237bc57081069c7 100644 (file)
@@ -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