File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,13 @@ func (p *Pool) revertWorker(worker *goWorker) bool {
259
259
worker .recycleTime = time .Now ()
260
260
p .lock .Lock ()
261
261
262
+ // To avoid memory leaks, add a double check in the lock scope.
263
+ // Issue: https://github.com/panjf2000/ants/issues/113
264
+ if atomic .LoadInt32 (& p .state ) == CLOSED {
265
+ p .lock .Unlock ()
266
+ return false
267
+ }
268
+
262
269
err := p .workers .insert (worker )
263
270
if err != nil {
264
271
p .lock .Unlock ()
Original file line number Diff line number Diff line change @@ -277,6 +277,14 @@ func (p *PoolWithFunc) revertWorker(worker *goWorkerWithFunc) bool {
277
277
}
278
278
worker .recycleTime = time .Now ()
279
279
p .lock .Lock ()
280
+
281
+ // To avoid memory leaks, add a double check in the lock scope.
282
+ // Issue: https://github.com/panjf2000/ants/issues/113
283
+ if atomic .LoadInt32 (& p .state ) == CLOSED {
284
+ p .lock .Unlock ()
285
+ return false
286
+ }
287
+
280
288
p .workers = append (p .workers , worker )
281
289
282
290
// Notify the invoker stuck in 'retrieveWorker()' of there is an available worker in the worker queue.
You can’t perform that action at this time.
0 commit comments