github-vet / github-vet/rangeloop-pointer-findings
cloudradar-monitoring/cagent: pkg/monitoring/networking/watcher.go; 30 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [cloudradar-monitoring/cagent](https://www.github.com/cloudradar-monitoring/cagent) at [pkg/monitoring/networking/watcher.go](https://github.com/cloudradar-monitoring/cagent/blob/b7373c1f18e555bdd0bf8e71150054f9133c44eb/pkg/monitoring/networking/watcher.go#L84-L113)
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 netIf at line 97 may start a goroutine
[Click here to see the code in its original context.](https://github.com/cloudradar-monitoring/cagent/blob/b7373c1f18e555bdd0bf8e71150054f9133c44eb/pkg/monitoring/networking/watcher.go#L84-L113)
Click here to show the 30 line(s) of Go which triggered the analyzer.
```go
for _, netIf := range allInterfaces {
// use a cache for excluded interfaces, because all the checks(except UP/DOWN state) are constant for the same interface&Config
if isExcluded, cacheExists := nw.constantlyExcludedInterfaceCache[netIf.Name]; cacheExists {
if isExcluded ||
nw.config.NetInterfaceExcludeDisconnected && isInterfaceDown(&netIf) {
// interface is found excluded in the cache or has a DOWN state
excludedInterfaces[netIf.Name] = struct{}{}
logrus.Debugf("[NET] interface excluded: %s", netIf.Name)
continue
}
} else {
if nw.config.NetInterfaceExcludeLoopback && isInterfaceLoobpack(&netIf) ||
nw.isInterfaceExcludedByName(&netIf) ||
nw.isInterfaceExcludedByRegexp(&netIf) {
// add the excluded interface to the cache because this checks are constant
nw.constantlyExcludedInterfaceCache[netIf.Name] = true
} else if nw.config.NetInterfaceExcludeDisconnected && isInterfaceDown(&netIf) {
// exclude DOWN interface for now
// lets cache it as false and then we will only check UP/DOWN status
nw.constantlyExcludedInterfaceCache[netIf.Name] = false
} else {
// interface is not excluded
nw.constantlyExcludedInterfaceCache[netIf.Name] = false
continue
}
excludedInterfaces[netIf.Name] = struct{}{}
logrus.Debugf("[NET] interface excluded: %s", netIf.Name)
}
}
```
Click here to show extra information the analyzer produced.
```
The following dot graph describes paths through the callgraph that could lead to a function calling a goroutine:
digraph G {
"(prepare, 2)" -> {"(New, 1)";}
"(load, 1)" -> {"(Open, 1)";}
"(Connect, 1)" -> {"(startWatcher, 0)";}
"(GetWatcher, 2)" -> {}
"(start, 0)" -> {"(DownloadAndInstallUpdate, 1)";}
"(Error, 0)" -> {"(BstrToString, 1)";"(Join, 2)";"(String, 0)";}
"(unmarshal, 2)" -> {"(New, 1)";"(prepare, 2)";"(scalar, 2)";"(mapping, 2)";"(sequence, 2)";}
"(value, 1)" -> {"(New, 1)";}
"(ReadTemperatureSensors, 0)" -> {"(readWMITemperatureSensors, 0)";}
"(Start, 1)" -> {"(RunHeartbeat, 1)";"(Run, 2)";}
"(startWatcher, 0)" -> {}
"(startMeasureProcessLoad, 1)" -> {"(GetProcesses, 1)";}
"(run, 0)" -> {}
"(StartChecking, 0)" -> {"(start, 0)";}
"(Run, 0)" -> {"(StartContinuousQuery, 2)";"(Start, 1)";"(Run, 2)";"(startMeasureProcessLoad, 1)";}
"(, 0)" -> {"(New, 1)";"(Logger, 1)";}
"(parse, 0)" -> {"(init, 0)";}
"(QueryWithTimeout, 4)" -> {}
"(Format, 1)" -> {"(Encode, 1)";}
"(Encode, 1)" -> {"(New, 1)";}
"(init, 0)" -> {"(New, 1)";}
"(SystemLogger, 1)" -> {"(Open, 1)";}
"(InterfaceExcludeRegexCompiled, 0)" -> {"(Error, 0)";}
"(detectTools, 1)" -> {"(checkTools, 1)";}
"(parseDocument, 0)" -> {"(New, 1)";}
"(GetProcesses, 1)" -> {}
"(DownloadAndInstallUpdate, 1)" -> {}
"(String, 0)" -> {"(Decode, 1)";"(Value, 0)";"(Format, 1)";}
"(sequence, 2)" -> {"(New, 1)";}
"(Open, 1)" -> {"(Connect, 1)";}
"(checkTools, 1)" -> {"(Run, 0)";}
"(Run, 2)" -> {"(run, 0)";"(collectMeasurements, 1)";}
"(collectMeasurements, 1)" -> {"(CPUUtilisationAnalyser, 0)";"(GetWatcher, 2)";"(ReadTemperatureSensors, 0)";"(CPUWatcher, 0)";}
"(BstrToString, 1)" -> {"(Decode, 1)";}
"(CPUUtilisationAnalyser, 0)" -> {}
"(mapping, 2)" -> {"(New, 1)";}
"(RunHeartbeat, 1)" -> {"(StartChecking, 0)";}
"(readWMITemperatureSensors, 0)" -> {"(QueryWithTimeout, 4)";}
"(New, 1)" -> {"(detectTools, 1)";"(load, 1)";}
"(GetVariantDate, 1)" -> {"(New, 1)";}
"(Join, 2)" -> {"(Value, 1)";}
"(Value, 1)" -> {"(value, 1)";}
"(scalar, 2)" -> {"(New, 1)";}
"(StartContinuousQuery, 2)" -> {}
"(Logger, 1)" -> {"(SystemLogger, 1)";}
"(CPUWatcher, 0)" -> {}
"(isInterfaceExcludedByRegexp, 1)" -> {"(InterfaceExcludeRegexCompiled, 0)";}
"(Decode, 1)" -> {"(, 0)";"(parseDocument, 0)";"(parse, 0)";"(unmarshal, 2)";}
"(Value, 0)" -> {"(GetVariantDate, 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: b7373c1f18e555bdd0bf8e71150054f9133c44eb
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.