mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
fix(warp): schedule pool timers under the pool lock
after() added to the pool wait group outside the lock, so a timer scheduled just as Close began Wait could be missed by the shutdown wait. Increment under the lock and refuse to schedule after Close, which removes the Add/Wait race.
This commit is contained in:
1 parent
54fe16ebb7
commit
a4ccac76b7
1 file changed
+10
-1
+10
-1
@@ -645,9 +645,18 @@ func (p *Pool) scaleDown() {
|
||||
}
|
||||
}
|
||||
|
||||
// after runs fn once delay has elapsed, unless the pool closes first.
|
||||
// after runs fn once delay has elapsed, unless the pool closes first. The wait
|
||||
// group is incremented under the pool lock so it cannot race with Close's
|
||||
// Wait: a timer scheduled after Close is not started at all, and one scheduled
|
||||
// before it is counted before Close can begin waiting.
|
||||
func (p *Pool) after(delay time.Duration, fn func()) {
|
||||
p.mu.Lock()
|
||||
if p.closed {
|
||||
p.mu.Unlock()
|
||||
return
|
||||
}
|
||||
p.wait.Add(1)
|
||||
p.mu.Unlock()
|
||||
go func() {
|
||||
defer p.wait.Done()
|
||||
timer := time.NewTimer(delay)
|
||||
|
||||
Reference in new issue
Block a user