fixed workers leak

This commit is contained in:
andy pan 2018-08-29 09:53:07 +08:00
parent 50918eb4a9
commit 8556a67f0f
2 changed files with 6 additions and 8 deletions

View File

@ -67,7 +67,7 @@ func (p *Pool) periodicallyPurge() {
p.lock.Unlock()
return
}
n := 0
n := -1
for i, w := range idleWorkers {
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
break
@ -76,12 +76,11 @@ func (p *Pool) periodicallyPurge() {
w.task <- nil
idleWorkers[i] = nil
}
n++
if n > 0 {
if n > -1 {
if n >= len(idleWorkers) {
p.workers = idleWorkers[:0]
} else {
p.workers = idleWorkers[n:]
p.workers = idleWorkers[n+1:]
}
}
p.lock.Unlock()

View File

@ -68,7 +68,7 @@ func (p *PoolWithFunc) periodicallyPurge() {
p.lock.Unlock()
return
}
n := 0
n := -1
for i, w := range idleWorkers {
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
break
@ -77,12 +77,11 @@ func (p *PoolWithFunc) periodicallyPurge() {
w.args <- nil
idleWorkers[i] = nil
}
n++
if n > 0 {
if n > -1 {
if n >= len(idleWorkers) {
p.workers = idleWorkers[:0]
} else {
p.workers = idleWorkers[n:]
p.workers = idleWorkers[n+1:]
}
}
p.lock.Unlock()