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

brokercap/Bifrost: server/history/select.go; 39 LoC

Open
#14,042 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 [brokercap/Bifrost](https://www.github.com/brokercap/Bifrost) at [server/history/select.go](https://github.com/brokercap/Bifrost/blob/92a5f48c1129eedab279306407f29baa527d048b/server/history/select.go#L211-L249)

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 toServer used in defer or goroutine at line 237

[Click here to see the code in its original context.](https://github.com/brokercap/Bifrost/blob/92a5f48c1129eedab279306407f29baa527d048b/server/history/select.go#L211-L249)

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

```go
for _,toServer := range This.ToServerList {
ToServerInfo := toServer.ToServerInfo
ToServerInfo.Lock()
status := ToServerInfo.Status
if status == "deling" || status == "deled" {
ToServerInfo.Unlock()
return
}
ToServerInfo.QueueMsgCount++
if ToServerInfo.ToServerChan == nil {
ToServerInfo.ToServerChan = &server.ToServerChan{
To: make(chan *pluginDriver.PluginDataType, config.ToServerQueueSize),
}
}
// 保证只要还有数据写入,就有最小的消费进程数量还在消费
toServer.Lock()
if toServer.threadCount < This.Property.SyncThreadNum {
// 为什么这里放一个协程去异步等待协程结束 ,而不是最开始初始化的时候,就启动呢
// 假如最开始初始化就启动了一个协程,但是假如拉取数据的协程,压根就没拉到数据,那等待同步协程结束 的 协程 不就是一直阻塞在那吗?
for i := 0; i < This.Property.SyncThreadNum-toServer.threadCount; i++ {
//每启用一个同步协程,就 +1 每个协程结束,就相对 -1
This.SyncWaitToServerOver(1)
toServer.threadCount++
go func() {
//这里要用 defer 是因为 ConsumeToServer 里 直接用了 runtime.Goexit()
defer func() {
toServer.Lock()
toServer.threadCount--
toServer.Unlock()
This.ToServerTheadGroup.Done()
}()
ToServerInfo.ConsumeToServer(server.GetDBObj(This.DbName), This.SchemaName, This.TableName)
}()
}
}
toServer.Unlock()
ToServerInfo.Unlock()
ToServerInfo.ToServerChan.To <- pluginData
}

```

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: 92a5f48c1129eedab279306407f29baa527d048b

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.