forked from mirror/ants
parent
ef60172172
commit
94a7a7f1cb
7
pool.go
7
pool.go
|
@ -259,6 +259,13 @@ func (p *Pool) revertWorker(worker *goWorker) bool {
|
||||||
worker.recycleTime = time.Now()
|
worker.recycleTime = time.Now()
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
|
||||||
|
// To avoid memory leaks, add a double check in the lock scope.
|
||||||
|
// Issue: https://github.com/panjf2000/ants/issues/113
|
||||||
|
if atomic.LoadInt32(&p.state) == CLOSED {
|
||||||
|
p.lock.Unlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
err := p.workers.insert(worker)
|
err := p.workers.insert(worker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
|
@ -277,6 +277,14 @@ func (p *PoolWithFunc) revertWorker(worker *goWorkerWithFunc) bool {
|
||||||
}
|
}
|
||||||
worker.recycleTime = time.Now()
|
worker.recycleTime = time.Now()
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
|
||||||
|
// To avoid memory leaks, add a double check in the lock scope.
|
||||||
|
// Issue: https://github.com/panjf2000/ants/issues/113
|
||||||
|
if atomic.LoadInt32(&p.state) == CLOSED {
|
||||||
|
p.lock.Unlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
p.workers = append(p.workers, worker)
|
p.workers = append(p.workers, worker)
|
||||||
|
|
||||||
// Notify the invoker stuck in 'retrieveWorker()' of there is an available worker in the worker queue.
|
// Notify the invoker stuck in 'retrieveWorker()' of there is an available worker in the worker queue.
|
||||||
|
|
Loading…
Reference in New Issue