bug: alleviate the data race between Release() and Reboot() (#333)

This commit is contained in:
Andy Pan 2024-06-18 03:05:09 +08:00 committed by GitHub
parent da22980e2c
commit b40e489286
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -135,9 +135,10 @@ func (p *Pool) ticktock() {
atomic.StoreInt32(&p.ticktockDone, 1) atomic.StoreInt32(&p.ticktockDone, 1)
}() }()
ticktockCtx := p.ticktockCtx // copy to the local variable to avoid race from Reboot()
for { for {
select { select {
case <-p.ticktockCtx.Done(): case <-ticktockCtx.Done():
return return
case <-ticker.C: case <-ticker.C:
} }

View File

@ -92,9 +92,10 @@ func (p *PoolWithFunc) ticktock() {
atomic.StoreInt32(&p.ticktockDone, 1) atomic.StoreInt32(&p.ticktockDone, 1)
}() }()
ticktockCtx := p.ticktockCtx // copy to the local variable to avoid race from Reboot()
for { for {
select { select {
case <-p.ticktockCtx.Done(): case <-ticktockCtx.Done():
return return
case <-ticker.C: case <-ticker.C:
} }