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

justbeatdruid/fusion: crds/api/controllers/sync_loop.go; 32 LoC

Open
#13,696 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 [justbeatdruid/fusion](https://www.github.com/justbeatdruid/fusion) at [crds/api/controllers/sync_loop.go](https://github.com/justbeatdruid/fusion/blob/b7793a503e226cd14996318cec1e3519f908529f/crds/api/controllers/sync_loop.go#L116-L147)

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.

> function call which takes a reference to value at line 145 may start a goroutine

[Click here to see the code in its original context.](https://github.com/justbeatdruid/fusion/blob/b7793a503e226cd14996318cec1e3519f908529f/crds/api/controllers/sync_loop.go#L116-L147)

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

```go
for _, value := range apiList.Items {
apiID := value.ObjectMeta.Name
needUpdateApi := false
if _, ok := countMap[apiID]; ok {
if value.Status.CalledCount != countMap[apiID] {
value.Status.CalledCount = countMap[apiID]
needUpdateApi = true
}
}
if _, ok := failedCountMap[apiID]; ok {
if value.Status.FailedCount != failedCountMap[apiID] {
value.Status.FailedCount = failedCountMap[apiID]
needUpdateApi = true
}
}
if _, ok := latencyCountMap[apiID]; ok {
if value.Status.LatencyCount != latencyCountMap[apiID] {
value.Status.LatencyCount = latencyCountMap[apiID]
needUpdateApi = true
}
}
if _, ok := callFrequencyMap[apiID]; ok {
if value.Status.CallFrequency != callFrequencyMap[apiID] {
value.Status.CallFrequency = callFrequencyMap[apiID]
needUpdateApi = true
}
}
if needUpdateApi {
klog.V(5).Infof("need update api count: %+v", value)
r.Update(ctx, &value)
}
}

```

Click here to show extra information the analyzer produced.

```
The following graphviz dot graph describes paths through the callgraph that could lead to a function calling a goroutine:
digraph G {
"(encoderOfMapKey, 2)" -> {"(encoderOfType, 2)";}
"(encoderOfStruct, 2)" -> {"(describeStruct, 2)";}
"(describeStruct, 2)" -> {"(append, 1)";}
"(configureTransport, 1)" -> {"(addConnIfNeeded, 3)";}
"(addConnIfNeeded, 3)" -> {}
"(update, 6)" -> {"(Convert, 2)";}
"(Convert, 2)" -> {"(Write, 1)";"(Decode, 2)";}
"(Write, 1)" -> {"(update, 1)";"(Decode, 1)";"(Encode, 2)";"(write, 1)";}
"(Decode, 2)" -> {"(Decode, 1)";"(Decode, 3)";}
"(encoderOfArray, 2)" -> {"(append, 1)";}
"(dispatch, 2)" -> {"(ProcessCallback, 2)";}
"(SetTransportDefaults, 1)" -> {"(ConfigureTransport, 1)";}
"(get, 1)" -> {"(SetTransportDefaults, 1)";}
"(Update, 5)" -> {"(update, 6)";}
"(update, 1)" -> {"(Update, 3)";"(Format, 1)";}
"(Format, 1)" -> {"(Encode, 1)";}
"(Encode, 2)" -> {"(encoderOfMapKey, 2)";}
"(append, 1)" -> {}
"(Add, 1)" -> {"(New, 1)";}
"(Decode, 3)" -> {"(Unmarshal, 1)";}
"(Decode, 1)" -> {"(logMessageDecode, 4)";}
"(_createEncoderOfType, 2)" -> {"(encoderOfSlice, 2)";"(encoderOfMap, 2)";"(createEncoderOfNative, 2)";"(encoderOfStruct, 2)";"(encoderOfArray, 2)";}
"(newClient, 1)" -> {}
"(Update, 3)" -> {"(Put, 4)";}
"(Encode, 1)" -> {"(Copy, 2)";}
"(Unmarshal, 1)" -> {"(unmarshalBody, 2)";}
"(ServeHTTP, 2)" -> {"(Dispatch, 2)";}
"(createEncoderOfType, 2)" -> {"(_createEncoderOfType, 2)";}
"(encoderOfSlice, 2)" -> {"(append, 1)";}
"(Update, 2)" -> {"(Add, 1)";"(Update, 5)";}
"(write, 1)" -> {"(Encode, 2)";}
"(createEncoderOfNative, 2)" -> {"(decoderOfSlice, 2)";}
"(decoderOfSlice, 2)" -> {"(append, 1)";}
"(ProcessCallback, 2)" -> {}
"(logMessageDecode, 4)" -> {"(Encode, 1)";}
"(encoderOfMap, 2)" -> {"(append, 1)";}
"(ConfigureTransport, 1)" -> {"(configureTransport, 1)";}
"(Put, 4)" -> {"(Copy, 2)";}
"(Copy, 2)" -> {"(ServeHTTP, 2)";}
"(unmarshalBody, 2)" -> {"(Copy, 2)";}
"(encoderOfType, 2)" -> {"(createEncoderOfType, 2)";}
"(Dispatch, 2)" -> {"(dispatch, 2)";}
"(New, 1)" -> {"(newClient, 1)";"(get, 1)";}
}

```

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

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.