github-vet / github-vet/rangeloop-pointer-findings
yooml/cgpsync: cgpsync.go; 20 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [yooml/cgpsync](https://www.github.com/yooml/cgpsync) at [cgpsync.go](https://github.com/yooml/cgpsync/blob/436fbd7b582596456a364f988b7f7661cae6bd15/cgpsync.go#L226-L245)
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 231
[Click here to see the code in its original context.](https://github.com/yooml/cgpsync/blob/436fbd7b582596456a364f988b7f7661cae6bd15/cgpsync.go#L226-L245)
Click here to show the 20 line(s) of Go which triggered the analyzer.
```go
for i :=range ch3{
ch4:=make(chan string,1)
sql_copyfrom:=fmt.Sprintf("copy %s from '/tmp/cgpsync/%d.pipe';",i.child_tbl_name,m)
go func() {
log.Println("开始同步表:",i.table_name,".",i.child_tbl_name)
copy_from(sql_copyfrom,i.child_tbl_name,ch4,i.table_name,db)
}()
echo:=fmt.Sprintf("psql -h %s -p %d -U %s -d %s -c 'copy %s to stdout' > /tmp/cgpsync/%d.pipe",
dbconfig.GetString("host"), dbconfig.GetInt("port"), dbconfig.GetString("user"), dbconfig.GetString("dbname"),i.child_tbl_name,m)
py :=exec.Command("/bin/bash","-c",echo)
stderr := &bytes.Buffer{}
py.Stderr = stderr
if err := py.Run(); err != nil {
fmt.Println("Error: ", err, "|", stderr.String())
}
<-ch4
ch2<-i.child_tbl_name
}
```
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: 436fbd7b582596456a364f988b7f7661cae6bd15
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.