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

PaaS-TA/PaaS-TA-Monitoring: iaas-paasta-monitoring-management/src/kr/paasta/monitoring/paas/service/container_service.go; 72 LoC

Open
#14,731 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [PaaS-TA/PaaS-TA-Monitoring](https://www.github.com/PaaS-TA/PaaS-TA-Monitoring) at [iaas-paasta-monitoring-management/src/kr/paasta/monitoring/paas/service/container_service.go](https://github.com/PaaS-TA/PaaS-TA-Monitoring/blob/6d85fd756a2ddcb6609ca9bcf82a470eb05e851d/iaas-paasta-monitoring-management/src/kr/paasta/monitoring/paas/service/container_service.go#L521-L592)

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 zone used in defer or goroutine at line 533

[Click here to see the code in its original context.](https://github.com/PaaS-TA/PaaS-TA-Monitoring/blob/6d85fd756a2ddcb6609ca9bcf82a470eb05e851d/iaas-paasta-monitoring-management/src/kr/paasta/monitoring/paas/service/container_service.go#L521-L592)

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

```go
for _, zone := range zonelist {
if zone.ZoneName == request.Name {

cells, _, _ := getZoneItemCount(cellist, zone.ZoneName)

var wg sync.WaitGroup
wg.Add(len(cells))

for _, cell := range cells {
go func(wg *sync.WaitGroup, cell model.ZoneCellInfo) {
var res model.ContainerRelationshipRes

res.ZoneName = zone.ZoneName
res.CellName = cell.CellName
res.Ip = cell.Ip

_, containers, _ := getZoneItemCount(cellist, zone.ZoneName)
if len(containers) > 0 {
var appInfoList []model.AppStatusInfo

for _, container := range containers {
if cell.CellName == container.CellName {
var apiRequest model.ContainerReq
apiRequest.CellIp = container.Ip
apiRequest.AppName = container.AppName
apiRequest.AppIndex = container.AppIndex
apiRequest.ContainerName = container.ContainerId
// select container monitoring
containerUsageRes, err := h.getContainerUsageState(apiRequest, serverThresholds)
if err != nil {
fmt.Println(err)
}

var appstate model.AppStatusInfo
appstate.AppName = containerUsageRes.AppName
appstate.AppIndex = containerUsageRes.AppIndex
appstate.Status = containerUsageRes.Status
appstate.ContainerId = containerUsageRes.ContainerName
appInfoList = append(appInfoList, appstate)
}
}

totalCnt, failedCnt, criticalCnt, warningCnt := len(appInfoList), 0, 0, 0

for _, value := range appInfoList {
if value.Status == model.STATE_FAILED {
failedCnt++
} else if value.Status == model.ALARM_LEVEL_CRITICAL {
criticalCnt++
} else if value.Status == model.ALARM_LEVEL_WARNING {
warningCnt++
}
}

res.RunningCnt = strconv.Itoa(totalCnt - failedCnt - criticalCnt - warningCnt)
res.FailCnt = strconv.Itoa(failedCnt)
res.CriticalCnt = strconv.Itoa(criticalCnt)
res.WarningCnt = strconv.Itoa(warningCnt)

res.ContainerCnt = strconv.Itoa(len(appInfoList))
res.AppCnt = strconv.Itoa(getContainerAppCount(appInfoList))
res.AppInfoList = appInfoList
}

result = append(result, res)

wg.Done()
}(&wg, cell)
}
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: 6d85fd756a2ddcb6609ca9bcf82a470eb05e851d

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.