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

yitouchashugu/xiaomaomi: memorySynchnorized/demo.go; 23 LoC

Open
#7,831 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 [yitouchashugu/xiaomaomi](https://www.github.com/yitouchashugu/xiaomaomi) at [memorySynchnorized/demo.go](https://github.com/yitouchashugu/xiaomaomi/blob/176b6bf6756b618cb7f2ab30b6bafe507918ae81/memorySynchnorized/demo.go#L38-L60)

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 s used in defer or goroutine at line 44

[Click here to see the code in its original context.](https://github.com/yitouchashugu/xiaomaomi/blob/176b6bf6756b618cb7f2ab30b6bafe507918ae81/memorySynchnorized/demo.go#L38-L60)

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

```go
for s := range req {
c, ok := cache[s.opt]
if !ok {
c = &cacheVal{b: nil, describe: "", ready: make(chan struct{})}
//do something to set value.使用串行操作太阻塞效率了,大家都在等所以改动过其中一部分进行并行操作
go func() {
b, err := HttpGet(s.opt)
if err != nil {
fmt.Println(err)
}

c.b = b
c.describe = "this is cache test"
close(c.ready)
}()
} else {
//ready channel实现了串行化操作,将同样的请求串行化为一个请求多次重试。减少无效请求的数量
//同样会阻塞后续的请求,因此最好放到一个goroutines中,因此正好放到deliver中。
//<-c.ready
}

go Deliver(c, s.resp)
}

```

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: 176b6bf6756b618cb7f2ab30b6bafe507918ae81

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.