Skip to content

Conversation

@ioworker0
Copy link
Contributor

@ioworker0 ioworker0 commented Oct 13, 2020

Fixes #113

@codecov
Copy link

codecov bot commented Oct 13, 2020

Codecov Report

Merging #114 into master will decrease coverage by 1.90%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #114      +/-   ##
==========================================
- Coverage   95.84%   93.94%   -1.91%     
==========================================
  Files           9        9              
  Lines         554      380     -174     
==========================================
- Hits          531      357     -174     
+ Misses         16       14       -2     
- Partials        7        9       +2     
Impacted Files Coverage Δ
pool.go 91.34% <100.00%> (-3.93%) ⬇️
pool_func.go 93.04% <100.00%> (-0.86%) ⬇️
ants.go 80.00% <0.00%> (-5.00%) ⬇️
worker_loop_queue.go 92.72% <0.00%> (-3.48%) ⬇️
worker.go 100.00% <0.00%> (ø)
options.go 100.00% <0.00%> (ø)
worker_func.go 100.00% <0.00%> (ø)
worker_array.go 100.00% <0.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef60172...00691c6. Read the comment docs.

@panjf2000
Copy link
Owner

panjf2000 commented Oct 14, 2020

Also please resolve this one:

ants/pool_func.go

Lines 274 to 286 in ad86bfa

func (p *PoolWithFunc) revertWorker(worker *goWorkerWithFunc) bool {
if atomic.LoadInt32(&p.state) == CLOSED || p.Running() > p.Cap() {
return false
}
worker.recycleTime = time.Now()
p.lock.Lock()
p.workers = append(p.workers, worker)
// Notify the invoker stuck in 'retrieveWorker()' of there is an available worker in the worker queue.
p.cond.Signal()
p.lock.Unlock()
return true
}

as well.

@panjf2000 panjf2000 added bug Something isn't working pending development Requested PR owner to improve code and waiting for the result waiting for response waiting for the response from commenter labels Oct 14, 2020
@ioworker0
Copy link
Contributor Author

Also please resolve this one:

ants/pool_func.go

Lines 274 to 286 in ad86bfa

func (p *PoolWithFunc) revertWorker(worker *goWorkerWithFunc) bool {
if atomic.LoadInt32(&p.state) == CLOSED || p.Running() > p.Cap() {
return false
}
worker.recycleTime = time.Now()
p.lock.Lock()
p.workers = append(p.workers, worker)
// Notify the invoker stuck in 'retrieveWorker()' of there is an available worker in the worker queue.
p.cond.Signal()
p.lock.Unlock()
return true
}

as well.

Sure, no problem

@ioworker0 ioworker0 mentioned this pull request Oct 15, 2020
Copy link
Owner

@panjf2000 panjf2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this bugfix is intuitive enough, no need to add unit tests, please remove it.

@ioworker0
Copy link
Contributor Author

I believe that this bugfix is intuitive enough, no need to add unit tests, please remove it.

Gotcha😃

@panjf2000 panjf2000 added pending merged This PR has been reviewed and approved and removed pending development Requested PR owner to improve code and waiting for the result waiting for response waiting for the response from commenter labels Oct 15, 2020
@panjf2000 panjf2000 merged commit 94a7a7f into panjf2000:master Oct 15, 2020
@panjf2000
Copy link
Owner

Thanks~

@ioworker0
Copy link
Contributor Author

Thanks~

@panjf2000
Bro, when will you consider adding a new tag?😃

@coticom
Copy link

coticom commented Apr 25, 2024

I have a point that I don't quite understand: After the double check, isn't it still possible that the pool might be closed? So, what's the purpose of this double check?

@OliverChao
Copy link

@coticom If the pool has been closed, revertWorker will never insert an un-released worker because of double check.

@ioworker0
Copy link
Contributor Author

I have a point that I don't quite understand: After the double check, isn't it still possible that the pool might be closed? So, what's the purpose of this double check?

IIUC, the first one looks more like is a best-effort early check. But it's
unreliable without the lock, so we also require the second one.

IOW, I don't believe that the first one is necessary in common cases :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pending merged This PR has been reviewed and approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Memory leak

4 participants