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

rzh/hammer.mongo: hammer/hammer.go; 35 LoC

Open
#15,942 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 [rzh/hammer.mongo](https://www.github.com/rzh/hammer.mongo) at [hammer/hammer.go](https://github.com/rzh/hammer.mongo/blob/fe6577a586e8ca62e03025a226bc68c2d082c38c/hammer/hammer.go#L308-L342)

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 319

[Click here to see the code in its original context.](https://github.com/rzh/hammer.mongo/blob/fe6577a586e8ca62e03025a226bc68c2d082c38c/hammer/hammer.go#L308-L342)

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

```go
for i, _ := range workers {
myid := atomic.AddInt32(&worker_id, 1)

if !silent {
log.Println("worker ", myid, " started")
}

if myid == 0 {
go func() {
_initdb_local := _initdb
if !silent {
log.Println("worker ", i, " initialization started")
}
_initdb = false
workers[myid].InitWorker(int(myid), mongo_server, _initdb_local, _profile, _total, dialInfo, nil) // just use array index as worker id, worker will NOT start running immediately
masterMgoSession = workers[0].GetMgoSession()

masterMgoSession = nil // not use mgo pool

if !silent {
log.Println("worker ", i, " initialization done, and wait for others")
}
sg.Done()
}()
} else {
// others will be false
go func() {
workers[myid].InitWorker(int(myid), mongo_server, false, _profile, _total, dialInfo, masterMgoSession) // just use array index as worker id, worker will NOT start running immediately
sg.Done() // I done
if !silent {
log.Println("worker ", myid, " initialization done, and wait for others")
}
}()
}
}

```

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.