Skip to content

Commit

Permalink
resourcemanager: avoid to get nil after task finished when to stop ta…
Browse files Browse the repository at this point in the history
…sk (#40699)

close #40700
  • Loading branch information
hawkingrei authored Jan 18, 2023
1 parent 95532bb commit 2944081
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions resourcemanager/pooltask/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ func (t *TaskManager[T, U, C, CT, TF]) StopTask(taskID uint64) {
shardID := getShardID(taskID)
t.task[shardID].rw.Lock()
defer t.task[shardID].rw.Unlock()
l := t.task[shardID].stats[taskID].stats
for e := l.Front(); e != nil; e = e.Next() {
e.Value.(tContainer[T, U, C, CT, TF]).task.SetStatus(StopTask)
// When call the StopTask, the task may have been deleted from the manager.
s, ok := t.task[shardID].stats[taskID]
if ok {
l := s.stats
for e := l.Front(); e != nil; e = e.Next() {
e.Value.(tContainer[T, U, C, CT, TF]).task.SetStatus(StopTask)
}
}
}
2 changes: 2 additions & 0 deletions util/gpool/spmc/spmcpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func TestStopPool(t *testing.T) {
control.Stop()
close(exit)
control.Wait()
// it should pass. Stop can be used after the pool is closed. we should prevent it from panic.
control.Stop()
wg.Wait()
// close pool
pool.ReleaseAndWait()
Expand Down

0 comments on commit 2944081

Please sign in to comment.