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

riderda/oa: main.go; 44 LoC

Open
#14,855 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 [riderda/oa](https://www.github.com/riderda/oa) at [main.go](https://github.com/riderda/oa/blob/ecac05fc0bea87218ffdfbd693c27989d724ef7e/main.go#L667-L710)

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 keyword used in defer or goroutine at line 674

[Click here to see the code in its original context.](https://github.com/riderda/oa/blob/ecac05fc0bea87218ffdfbd693c27989d724ef7e/main.go#L667-L710)

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

```go
for keyword := range ch{
data.Keyword += keyword+";"
wg.Add(2)
//估计查询量比较大,使用并发查找
go func(){
//长度更新
defer wg.Done()
templength, err := dbs.GetLengthOfBlog(keyword,Db)
if err != nil{
log.Println("query is error",err.Error())
w.WriteHeader(500)
return
}
data.Info.Length += templength
}()

go func(){
//内容更新
defer wg.Done()
dbBlogList, err := dbs.GetBlogLimitBy(keyword,Limit,Db)
if err != nil{
log.Println("query is error",err.Error())
w.WriteHeader(500)
return
}

for _, blog := range dbBlogList{
temp := back.Blog{
Id: blog.Id,
Keyword: blog.Keyword,
Title: blog.Title,
Content: blog.Content,
Summary: blog.Summary,
Author: blog.Author,
Record: blog.Record,
PublicStatus: blog.PublicStatus,
PublicTime: blog.PublicTime,
IsShow: blog.IsShow,
}
data.BlogListByKeyword = append(data.BlogListByKeyword,temp)
}

}()
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading main.go lines 667-710, especially the goroutines launched inside the range loop, and inspect how keyword is used there. Check the project's available tests or analyzer against this code; done means the reported range-loop capture issue is resolved without changing the intended database-query behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.