github-vet / github-vet/rangeloop-pointer-findings
liyanyanli/hch: api/replication_policy.go; 21 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [liyanyanli/hch](https://www.github.com/liyanyanli/hch) at [api/replication_policy.go](https://github.com/liyanyanli/hch/blob/66d80b90d349dad61024bc5ab2ed3d8fd2e36e40/api/replication_policy.go#L474-L494)
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 repo used in defer or goroutine at line 480
[Click here to see the code in its original context.](https://github.com/liyanyanli/hch/blob/66d80b90d349dad61024bc5ab2ed3d8fd2e36e40/api/replication_policy.go#L474-L494)
Click here to show the 21 line(s) of Go which triggered the analyzer.
```go
for repo, _ := range policy.Image {
tags := policy.Image[repo]
//log.Infof("***************repo***************%s", repo)
go func() {
ch <- 1
//log.Infof("***************start***************%s", repo)
if err := TriggerReplication(pid, repo, tags, models.RepOpTransfer); err != nil {
log.Errorf("failed to trigger replication of %d: %v", pid, err)
} else {
log.Infof("replication of %d triggered", pid)
}
}()
select {
case <-ch:
case <-time.After(10 * time.Second):
log.Errorf("failed to start current replication,repoNmae%s", repo)
continue
//panic("Failed to start after 10 seconds")
}
//log.Infof("***************end***************%s", repo)
}
```
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: 66d80b90d349dad61024bc5ab2ed3d8fd2e36e40
Contributor guide
No contributing guide indexed for this repository
Research direction
Read api/replication_policy.go lines 474-494 and review Go range-loop variable capture in the goroutine. Decide whether the reported use of repo can trigger incorrect replication behavior, then classify the finding as Bug, Mitigated, or Desirable Behavior using the linked guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 40/100