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

newrelic/nri-flex: internal/discovery/fargate.go; 39 LoC

Open
#11,099 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 [newrelic/nri-flex](https://www.github.com/newrelic/nri-flex) at [internal/discovery/fargate.go](https://github.com/newrelic/nri-flex/blob/1724c16a52dcbbc92d5d33b3d878f210ae51cb34/internal/discovery/fargate.go#L58-L96)

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 currentConfig used in defer or goroutine at line 79

[Click here to see the code in its original context.](https://github.com/newrelic/nri-flex/blob/1724c16a52dcbbc92d5d33b3d878f210ae51cb34/internal/discovery/fargate.go#L58-L96)

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

```go
for _, currentConfig := range *configs {
if strings.HasPrefix(currentConfig.FileName, "cd-") {
if currentConfig.ContainerDiscovery.Mode == "" {
currentConfig.ContainerDiscovery.Mode = "contains"
}
if currentConfig.ContainerDiscovery.Type == "" {
currentConfig.ContainerDiscovery.Type = load.TypeContainer
}
if currentConfig.ContainerDiscovery.Target == "" {
target := strings.Replace(strings.TrimPrefix(currentConfig.FileName, "cd-"), ".yml", "", -1)
currentConfig.ContainerDiscovery.Target = strings.Replace(target, ".yaml", "", -1)
}

// check all containers async
var wg sync.WaitGroup
wg.Add(len(TaskMetadata.Containers))
for _, container := range TaskMetadata.Containers {
go func(container load.Container) {
defer wg.Done()
// do not target the flex container
if container.DockerID != load.ContainerID {
if checkContainerMatch(container, currentConfig.ContainerDiscovery) {
load.Logrus.Debugf("discovery: fargate lookup matched %v - file %v", container.DockerID, currentConfig.FileName)
if len(container.Networks) > 0 {
if len(container.Networks[0].IPv4Addresses) > 0 {
addDynamicFargateConfig(configs, currentConfig, container)
} else {
load.Logrus.Debugf("discovery: fargate container %v file %v - does not have any IPv4 Addresses configured", container.DockerID, currentConfig.FileName)
}
} else {
load.Logrus.Debugf("discovery: fargate container %v file %v - does not have any networks configured", container.DockerID, currentConfig.FileName)
}
}
}
}(container)
}
wg.Wait()
}
}

```

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: 1724c16a52dcbbc92d5d33b3d878f210ae51cb34

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.