Skip to content

Commit

Permalink
bug: alleviate the data race between Release() and Reboot()
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Jun 17, 2024
1 parent da22980 commit d5724a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ func (p *Pool) ticktock() {
atomic.StoreInt32(&p.ticktockDone, 1)
}()

ticktockCtx := p.ticktockCtx // copy to the local variable to avoid race from Reboot()
for {
select {
case <-p.ticktockCtx.Done():
case <-ticktockCtx.Done():
return
case <-ticker.C:
}
Expand Down
3 changes: 2 additions & 1 deletion pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func (p *PoolWithFunc) ticktock() {
atomic.StoreInt32(&p.ticktockDone, 1)
}()

ticktockCtx := p.ticktockCtx // copy to the local variable to avoid race from Reboot()
for {
select {
case <-p.ticktockCtx.Done():
case <-ticktockCtx.Done():
return
case <-ticker.C:
}
Expand Down

0 comments on commit d5724a2

Please sign in to comment.