github-vet / github-vet/rangeloop-pointer-findings
CecBazinga/WBMQSystemProject: http-api.go; 58 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [CecBazinga/WBMQSystemProject](https://www.github.com/CecBazinga/WBMQSystemProject) at [http-api.go](https://github.com/CecBazinga/WBMQSystemProject/blob/fbf49445475bc71a030ae9febe68c5b77f51a4e6/http-api.go#L260-L317)
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 requestItem used in defer or goroutine at line 268
[Click here to see the code in its original context.](https://github.com/CecBazinga/WBMQSystemProject/blob/fbf49445475bc71a030ae9febe68c5b77f51a4e6/http-api.go#L260-L317)
Click here to show the 58 line(s) of Go which triggered the analyzer.
```go
for _, requestItem := range requestSlice {
mainWg.Add(1)
go func(mySensor Sensor) {
var wg sync.WaitGroup
myRequestItem := requestItem
requestResilienceEntries := []resilienceEntry{}
var sensor Sensor
sensor.Id = myRequestItem.Id
sensor.Message = myRequestItem.Message
sensor.Type = myRequestItem.Type
sensor.Pbrtx = myRequestItem.Pbrtx
sensor.CurrentSector = myRequestItem.CurrentSector
//for every request creates the list of its own resilience entries
for _, resilienceItem := range resilience {
if resilienceItem.Message == sensor.Message && strings.Contains(resilienceItem.Id, sensor.Id) {
requestResilienceEntries = append(requestResilienceEntries, resilienceItem)
}
}
if len(requestResilienceEntries) > 0 {
//retransmit the request to every entry
for _, resilienceItem := range requestResilienceEntries {
myBot := findBotbyId(strings.ReplaceAll(resilienceItem.Id, myRequestItem.Id, ""))
if myBot.Id == "" {
panic("NO BOT ASSOCIATED WITH THIS RESILIENCE ENTRY : SOMETHING WRONG ")
} else if myBot.Id != "" {
wg.Add(1)
go publishImplementation(myBot, sensor, &wg)
}
}
//awaits for all subroutines to end with an ack
wg.Wait()
}
removePubRequest(sensor.Id, sensor.Message)
mainWg.Done()
}(requestItem)
}
```
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: fbf49445475bc71a030ae9febe68c5b77f51a4e6
Contributor guide
No contributing guide indexed for this repository
Research direction
Open http-api.go at lines 260-317 in the linked commit and inspect how requestItem is used inside the goroutine, especially the assignment to myRequestItem. Compare that behavior with the range-loop capture warning, then react with Bug, Mitigated, or Desirable Behavior; done means a supported classification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100