Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resourcemanager: avoid to get nil after task finished when to stop task #40699

Merged
merged 3 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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