github-vet / github-vet/rangeloop-pointer-findings
mattermost/mmctl: commands/webhook.go; 38 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [mattermost/mmctl](https://www.github.com/mattermost/mmctl) at [commands/webhook.go](https://github.com/mattermost/mmctl/blob/689bd041b5aa02183721fda0c4e9a4e3d84fab15/commands/webhook.go#L101-L138)
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 team used in defer or goroutine at line 110
[Click here to see the code in its original context.](https://github.com/mattermost/mmctl/blob/689bd041b5aa02183721fda0c4e9a4e3d84fab15/commands/webhook.go#L101-L138)
Click here to show the 38 line(s) of Go which triggered the analyzer.
```go
for i, team := range teams {
if team == nil {
printer.PrintError("Unable to find team '" + args[i] + "'")
continue
}
// Fetch all hooks with a very large limit so we get them all.
incomingResult := make(chan StoreResult, 1)
go func() {
incomingHooks, response := c.GetIncomingWebhooksForTeam(team.Id, 0, 100000000, "")
incomingResult <- StoreResult{Data: incomingHooks, Err: response.Error}
close(incomingResult)
}()
outgoingResult := make(chan StoreResult, 1)
go func() {
outgoingHooks, response := c.GetOutgoingWebhooksForTeam(team.Id, 0, 100000000, "")
outgoingResult <- StoreResult{Data: outgoingHooks, Err: response.Error}
close(outgoingResult)
}()
if result := <-incomingResult; result.Err == nil {
hooks := result.Data.([]*model.IncomingWebhook)
for _, hook := range hooks {
printer.PrintT("Incoming:\t{{.DisplayName}} ({{.Id}}", hook)
}
} else {
printer.PrintError("Unable to list incoming webhooks for '" + team.Id + "'")
}
if result := <-outgoingResult; result.Err == nil {
hooks := result.Data.([]*model.OutgoingWebhook)
for _, hook := range hooks {
printer.PrintT("Outgoing:\t {{.DisplayName}} ({{.Id}})", hook)
}
} else {
printer.PrintError("Unable to list outgoing webhooks for '" + team.Id + "'")
}
}
```
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: 689bd041b5aa02183721fda0c4e9a4e3d84fab15
Contributor guide
No contributing guide indexed for this repository
Research direction
Inspect commands/webhook.go at lines 101-138, especially the two goroutines inside the team loop, and review the range-loop capture analyzer finding. Done means each goroutine uses the intended team for its iteration and the reported analyzer issue is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100