github-vet / github-vet/rangeloop-pointer-findings
didip/mcrouter-hub: application/application.go; 61 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [didip/mcrouter-hub](https://www.github.com/didip/mcrouter-hub) at [application/application.go](https://github.com/didip/mcrouter-hub/blob/c74e3af77ee9246c5f5f49cf81972b715825a823/application/application.go#L254-L314)
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 url used in defer or goroutine at line 275
[Click here to see the code in its original context.](https://github.com/didip/mcrouter-hub/blob/c74e3af77ee9246c5f5f49cf81972b715825a823/application/application.go#L254-L314)
Click here to show the 61 line(s) of Go which triggered the analyzer.
```go
for _, url := range app.CentralURLs() {
if !strings.HasSuffix(url, "/configs") {
url = url + "/configs"
}
go func() {
for {
tokens := app.Tokens()
run := func(token string) error {
configInterface := app.Storage.Get("config")
if configInterface == nil {
return err
}
config := configInterface.(map[string]interface{})
payload := &payloads.ReportConfigToCentralPayload{Hostname: hostname, Config: config}
payloadJson, err := json.Marshal(payload)
req, err := http.NewRequest("POST", url, bytes.NewReader(payloadJson))
if err != nil {
logrus.WithFields(logrus.Fields{
"Error": err.Error(),
}).Error("Failed to create HTTP request struct")
return err
}
req.Header.Set("Content-Type", "application/json")
if token != "" {
req.SetBasicAuth(token, "")
}
resp, err := client.Do(req)
if err != nil {
logrus.WithFields(logrus.Fields{
"Error": err.Error(),
}).Error("Failed to send HTTP request")
return err
}
defer resp.Body.Close()
return nil
}
if len(tokens) == 0 {
run("")
} else {
for _, token := range tokens {
run(token)
}
}
time.Sleep(duration)
}
}()
}
```
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: c74e3af77ee9246c5f5f49cf81972b715825a823
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.