add mutex around modifying runner count (#12778)

pull/12777/head
Lyon Hill 2019-03-20 10:40:13 -06:00 committed by GitHub
parent 2ae969b31d
commit 49d025ba64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -352,6 +352,7 @@ func (s *TickScheduler) UpdateTask(task *StoreTask, meta *StoreTaskMeta) error {
// todo(lh): In the near future we may not be using the scheduler to manage concurrency.
maxC := int(meta.MaxConcurrency)
if maxC != len(ts.runners) {
ts.runningMu.Lock()
if maxC < len(ts.runners) {
ts.runners = ts.runners[:maxC]
}
@ -362,6 +363,7 @@ func (s *TickScheduler) UpdateTask(task *StoreTask, meta *StoreTaskMeta) error {
ts.runners = append(ts.runners, newRunner(s.ctx, ts.wg, s.logger, task, s.desiredState, s.executor, s.logWriter, ts))
}
}
ts.runningMu.Unlock()
}
if now := atomic.LoadInt64(&s.now); now >= next || hasQueue {
ts.Work()