1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:04:41 -07:00

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
This commit is contained in:
Philip Roberts 2023-02-13 13:45:00 +00:00
parent 71c84d4b41
commit 0d149d8d38

View File

@ -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: