Skip to content

Commit 7b26389

Browse files
latentflipgopherbot
authored andcommitted
database/sql: wake cleaner if maxIdleTime set to less than maxLifetime
The existing implementation wouldn't wake the connection cleaner if maxIdleTime was set to a value less than maxLifetime while an existing connection was open - resulting in idle connections not being discarded until after the first maxLifetime had passed. Fixes #45993 Change-Id: I074ed7ba9803354c8b3a41f2625ae0d8a7d5059b GitHub-Last-Rev: 0d149d8 GitHub-Pull-Request: #58490 Reviewed-on: https://go-review.googlesource.com/c/go/+/467655 Auto-Submit: Sean Liao <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Sean Liao <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Daniel Theophanes <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 3cefe69 commit 7b26389

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/database/sql/sql.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ func (db *DB) SetConnMaxLifetime(d time.Duration) {
10501050
}
10511051
db.mu.Lock()
10521052
// Wake cleaner up when lifetime is shortened.
1053-
if d > 0 && d < db.maxLifetime && db.cleanerCh != nil {
1053+
if d > 0 && d < db.shortestIdleTimeLocked() && db.cleanerCh != nil {
10541054
select {
10551055
case db.cleanerCh <- struct{}{}:
10561056
default:
@@ -1074,7 +1074,7 @@ func (db *DB) SetConnMaxIdleTime(d time.Duration) {
10741074
defer db.mu.Unlock()
10751075

10761076
// Wake cleaner up when idle time is shortened.
1077-
if d > 0 && d < db.maxIdleTime && db.cleanerCh != nil {
1077+
if d > 0 && d < db.shortestIdleTimeLocked() && db.cleanerCh != nil {
10781078
select {
10791079
case db.cleanerCh <- struct{}{}:
10801080
default:

0 commit comments

Comments
 (0)