mirror of https://github.com/panjf2000/ants.git
fixed workers leak
This commit is contained in:
parent
50918eb4a9
commit
8556a67f0f
7
pool.go
7
pool.go
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue