github-vet / github-vet/rangeloop-pointer-findings
zuston/AtcalMq: backuper.go; 37 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [zuston/AtcalMq](https://www.github.com/zuston/AtcalMq) at [backuper.go](https://github.com/zuston/AtcalMq/blob/4eb86440cfac5214e60b4b67d1038963168fb1a4/backuper.go#L121-L157)
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 filePath used in defer or goroutine at line 123
[Click here to see the code in its original context.](https://github.com/zuston/AtcalMq/blob/4eb86440cfac5214e60b4b67d1038963168fb1a4/backuper.go#L121-L157)
Click here to show the 37 line(s) of Go which triggered the analyzer.
```go
for _, filePath := range files{
go func() {
queueName,YMD := parse(filePath)
if *savingTag {
queueName = fmt.Sprintf("%s_%s",core.SAVING_RELATION_PREFIX,queueName)
}
startTime := time.Now()
_ = YMD
file, err := os.Open(filePath)
// 恢复机制,记录点
util.CheckPanic(err)
defer func() {
file.Close()
barrier.Done()
}()
reader := bufio.NewReader(file)
for {
line, err := readLine(reader)
if err!=nil {
break
}
//infoTag := line[0:22]
info := line[22:]
//fmt.Println(infoTag,info)
infoChannel <- backuperStruct{
// todo 是二元关系存储还是备份的。更改queue的前缀
queueName:queueName,
info:info,
}
}
endTime := time.Now()
fmt.Printf("[%s] reading cost : [%s]\n",queueName,endTime.Sub(startTime))
}()
}
```
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: 4eb86440cfac5214e60b4b67d1038963168fb1a4
Contributor guide
No contributing guide indexed for this repository
Research direction
Open backuper.go at lines 121-157 and inspect how filePath is used inside the goroutine and deferred cleanup. Read the linked range-loop-capture classification guidance and determine whether different iterations can observe the wrong path. Done means leaving the appropriate reaction classification on the issue.
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
- Mostly clear
- Newbie friendliness
- 35/100