mirror of
https://github.com/golang/go
synced 2024-11-21 21:24:45 -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:
parent
71c84d4b41
commit
0d149d8d38
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user