github-vet / github-vet/rangeloop-pointer-findings
zaddone/RoutineWork: server/Server.go; 26 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [zaddone/RoutineWork](https://www.github.com/zaddone/RoutineWork) at [server/Server.go](https://github.com/zaddone/RoutineWork/blob/7f0703972165d48fc04374f9a29200ea371cec90/server/Server.go#L32-L57)
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 inc used in defer or goroutine at line 43
[Click here to see the code in its original context.](https://github.com/zaddone/RoutineWork/blob/7f0703972165d48fc04374f9a29200ea371cec90/server/Server.go#L32-L57)
Click here to show the 26 line(s) of Go which triggered the analyzer.
```go
for _, inc := range replay.InsCaches {
if inc.Ins.Name == InsName.Name {
log.Println(InsName, "lastTime")
ser := new(replay.ServerChan)
ctx, cancel := context.WithCancel(context.Background())
ser.Init(ctx)
key := int(time.Now().UnixNano())
inc.ServerChanMap.Add(key,ser)
defer func() {
log.Println("lastTime over")
inc.ServerChanMap.Del(key)
cancel()
}()
return ser.Out(func(ti *replay.TimeCache) error {
return stream.Send(&pb.LastTime{
Tag: ti.Name,
Scale: ti.Scale,
Time: ti.Time})
})
}
}
```
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: 7f0703972165d48fc04374f9a29200ea371cec90
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with server/Server.go at lines 32-57 and inspect the reported range-loop variable use in the deferred function. Compare the analyzer warning with the surrounding control flow; done means documenting whether this is a bug, mitigated, or desirable behavior and leaving the requested reaction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100