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

Bnei-Baruch/gxydb-api: instrumentation/periodic.go; 30 LoC

Open
#15,349 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 [Bnei-Baruch/gxydb-api](https://www.github.com/Bnei-Baruch/gxydb-api) at [instrumentation/periodic.go](https://github.com/Bnei-Baruch/gxydb-api/blob/aefbef8710f063b97380a4cf410a3c15b1cfdf44/instrumentation/periodic.go#L102-L131)

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 gateway used in defer or goroutine at line 104

[Click here to see the code in its original context.](https://github.com/Bnei-Baruch/gxydb-api/blob/aefbef8710f063b97380a4cf410a3c15b1cfdf44/instrumentation/periodic.go#L102-L131)

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

```go
for _, gateway := range gateways {
go func(g *models.Gateway, c chan *gatewayCallRes) {
res := &gatewayCallRes{gateway: g}
start := time.Now()
defer func() {
res.duration = time.Now().Sub(start)
c <- res
}()

api, err := domain.GatewayAdminAPIRegistry.For(g)
if err != nil {
res.err = pkgerr.Wrap(err, "domain.GatewayAdminAPIRegistry.For")
return
}

apiRes, err := api.ListSessions()
if err != nil {
res.err = pkgerr.Wrap(err, "api.ListSessions")
return
}

tApiRes, ok := apiRes.(*janus_admin.ListSessionsResponse)
if !ok {
res.err = pkgerr.Errorf("unexpected api.ListSessions response: %+v", apiRes)
return
}

res.sessions = len(tApiRes.Sessions)
}(gateway, c)
}

```

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: aefbef8710f063b97380a4cf410a3c15b1cfdf44

Contributor guide

No contributing guide indexed for this repository

Research direction

Read instrumentation/periodic.go around lines 102-131 and trace how gateway is passed into the goroutine and used by the deferred function. Confirm whether each goroutine operates on the intended gateway and determine whether the analyzer warning reflects a real defect. Done means the finding is resolved or documented as safe, with relevant Go tests or checks passing.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.