From 0d149d8d38bc9c2ad42a2a20dcfc73994d54fe23 Mon Sep 17 00:00:00 2001 From: Philip Roberts Date: Mon, 13 Feb 2023 13:45:00 +0000 Subject: [PATCH] database/sql: wake cleaner when maxIdleTime less than maxLifetime The existing implementation wouldn't wake the connection cleaner if maxIdleTime was set to a value less than maxLifetime resulting in idle connections being held on to longer than expected. Fixes #45993 --- src/database/sql/sql.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index ad17eb3da2c..8a531ca4677 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -1007,7 +1007,7 @@ func (db *DB) SetConnMaxLifetime(d time.Duration) { } db.mu.Lock() // Wake cleaner up when lifetime is shortened. - if d > 0 && d < db.maxLifetime && db.cleanerCh != nil { + if d > 0 && d < db.shortestIdleTimeLocked() && db.cleanerCh != nil { select { case db.cleanerCh <- struct{}{}: default: @@ -1031,7 +1031,7 @@ func (db *DB) SetConnMaxIdleTime(d time.Duration) { defer db.mu.Unlock() // Wake cleaner up when idle time is shortened. - if d > 0 && d < db.maxIdleTime && db.cleanerCh != nil { + if d > 0 && d < db.shortestIdleTimeLocked() && db.cleanerCh != nil { select { case db.cleanerCh <- struct{}{}: default: