From b40e489286d17a26c88461e70e018fabefa23c95 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Tue, 18 Jun 2024 03:05:09 +0800 Subject: [PATCH] bug: alleviate the data race between Release() and Reboot() (#333) --- pool.go | 3 ++- pool_func.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pool.go b/pool.go index 9c28874..33e46ed 100644 --- a/pool.go +++ b/pool.go @@ -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: } diff --git a/pool_func.go b/pool_func.go index a73d979..140d5fe 100644 --- a/pool_func.go +++ b/pool_func.go @@ -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: }