github-vet / github-vet/rangeloop-pointer-findings

reborndb/reborn: cmd/agent/ha.go; 25 LoC

Open
#18,190 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [reborndb/reborn](https://www.github.com/reborndb/reborn) at [cmd/agent/ha.go](https://github.com/reborndb/reborn/blob/70285c89f88225d4b1840697d2d6133c2a1aa605/cmd/agent/ha.go#L175-L199)

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 agent used in defer or goroutine at line 186

[Click here to see the code in its original context.](https://github.com/reborndb/reborn/blob/70285c89f88225d4b1840697d2d6133c2a1aa605/cmd/agent/ha.go#L175-L199)

Click here to show the 25 line(s) of Go which triggered the analyzer.

```go
for i, agent := range agents {
if agent.ID == agentID {
// ignore itself
reply[i] = nil
continue
}

wg.Add(1)
go func(i int) {
defer wg.Done()

resp, err := http.Get(fmt.Sprintf("http://%s/api/check_store?addr=%s", agent.Addr, s.Addr))
if err != nil {
reply[i] = errors.Trace(err)
return
}
defer resp.Body.Close()
if _, err = ioutil.ReadAll(resp.Body); err != nil {
reply[i] = errors.Trace(err)
return
}

reply[i] = int(resp.StatusCode)
}(i)
}

```

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: 70285c89f88225d4b1840697d2d6133c2a1aa605

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in cmd/agent/ha.go at lines 175-199 and read the analyzer's range-loop finding around the goroutine. Trace how each agent is used in the request and how reply[i] is populated; done means the reported capture issue is resolved without changing the intended per-agent replies. No test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.