The problem of golang array out of bounds

task is a [] string
Delete is a secure delete method for task, and there are also Push and other methods..

for{
    select{
        case <-chan:
            return
        case <-time.After(time.Second * 5):
            if(len(task) > 0){
                arr := make([]string,len(task))
                copy(arr,task)
                for k, v := range arr{
                    ....
                    task.Delete(k)
                }
            }
    }
}

if you run this way for a period of time, you will get an error that task deletion is out of bounds.
what"s wrong with this code?

Feb.28,2022

how Delete is safe.. Where do you lock it?

Menu