github-vet / github-vet/rangeloop-pointer-findings
miku/esbulk: cmd/esbulk/esbulk.go; 46 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [miku/esbulk](https://www.github.com/miku/esbulk) at [cmd/esbulk/esbulk.go](https://github.com/miku/esbulk/blob/bc79561fe167874f254180a0c8ffae54cc90dfc1/cmd/esbulk/esbulk.go#L192-L237)
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 i used in defer or goroutine at line 218
[Click here to see the code in its original context.](https://github.com/miku/esbulk/blob/bc79561fe167874f254180a0c8ffae54cc90dfc1/cmd/esbulk/esbulk.go#L192-L237)
Click here to show the 46 line(s) of Go which triggered the analyzer.
```go
for i, _ := range options.Servers {
// Store number_of_replicas settings for restoration later.
doc, err := esbulk.GetSettings(i, options)
if err != nil {
log.Fatal(err)
}
// TODO(miku): Rework this.
numberOfReplicas := doc[options.Index].(map[string]interface{})["settings"].(map[string]interface{})["index"].(map[string]interface{})["number_of_replicas"]
if *verbose {
log.Printf("on shutdown, number_of_replicas will be set back to %s", numberOfReplicas)
}
if *verbose {
log.Printf("on shutdown, refresh_interval will be set back to %s", *refreshInterval)
}
// Shutdown procedure. TODO(miku): Handle signals, too.
defer func() {
// Realtime search.
if _, err := indexSettingsRequest(fmt.Sprintf(`{"index": {"refresh_interval": "%s"}}`, *refreshInterval), options); err != nil {
log.Fatal(err)
}
// Reset number of replicas.
if _, err := indexSettingsRequest(fmt.Sprintf(`{"index": {"number_of_replicas": %q}}`, numberOfReplicas), options); err != nil {
log.Fatal(err)
}
// Persist documents.
if err := esbulk.FlushIndex(i, options); err != nil {
log.Fatal(err)
}
}()
// Realtime search.
resp, err := indexSettingsRequest(`{"index": {"refresh_interval": "-1"}}`, options)
if err != nil {
log.Fatal(err)
}
if resp.StatusCode >= 400 {
log.Fatal(resp)
}
if *zeroReplica {
// Reset number of replicas.
if _, err := indexSettingsRequest(`{"index": {"number_of_replicas": 0}}`, options); err != nil {
log.Fatal(err)
}
}
}
```
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: bc79561fe167874f254180a0c8ffae54cc90dfc1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.