github-vet / github-vet/rangeloop-pointer-findings
emc-advanced-dev/layerx: layerx-core/fakes/fake_lx_server.go; 40 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [emc-advanced-dev/layerx](https://www.github.com/emc-advanced-dev/layerx) at [layerx-core/fakes/fake_lx_server.go](https://github.com/emc-advanced-dev/layerx/blob/c76ca947d4d4d604041c5c09d56bf8bcb998c3ca/layerx-core/fakes/fake_lx_server.go#L575-L614)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable taskId used in defer or goroutine at line 610
[Click here to see the code in its original context.](https://github.com/emc-advanced-dev/layerx/blob/c76ca947d4d4d604041c5c09d56bf8bcb998c3ca/layerx-core/fakes/fake_lx_server.go#L575-L614)
Click here to show the 40 line(s) of Go which triggered the analyzer.
```go
for _, taskId := range migrateMessage.TaskIds {
var task *lxtypes.Task
var sourceNode *lxtypes.Node
for _, node := range core.Nodes {
logrus.WithFields(logrus.Fields{"task_id": taskId, "node": node}).Infof("searching node for task")
task = node.GetTask(taskId)
sourceNode = node
if task != nil {
break
}
}
if task == nil {
logrus.WithFields(logrus.Fields{"task_id": taskId, "core.Nodes": core.Nodes}).Errorf("invalid task id")
res.WriteHeader(400)
return
}
task.NodeId = migrateMessage.DestinationNodeId
err = sourceNode.RemoveTask(taskId)
if err != nil {
logrus.WithFields(logrus.Fields{"task_id": taskId, "node": sourceNode}).Errorf("could not remove task from node")
res.WriteHeader(400)
return
}
core.StagingTasks[taskId] = task
go func() {
logrus.Debugf("in 3 seconds, moving from staging to running on the node")
time.Sleep(1 * time.Second)
err = targetNode.AddTask(task)
if err != nil {
logrus.WithFields(logrus.Fields{
"node_id": task.NodeId,
}).Errorf("could not add task to node")
res.WriteHeader(400)
return
} else {
delete(core.StagingTasks, taskId)
}
}()
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: c76ca947d4d4d604041c5c09d56bf8bcb998c3ca
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.