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

NCCloud/fluid: internal/ingress/controller/controller.go; 52 LoC

Open
#11,210 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 [NCCloud/fluid](https://www.github.com/NCCloud/fluid) at [internal/ingress/controller/controller.go](https://github.com/NCCloud/fluid/blob/1167665ac94e07c04ad868381192090a2b51679b/internal/ingress/controller/controller.go#L539-L590)

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 sm used in defer or goroutine at line 542

[Click here to see the code in its original context.](https://github.com/NCCloud/fluid/blob/1167665ac94e07c04ad868381192090a2b51679b/internal/ingress/controller/controller.go#L539-L590)

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

```go
for _, sm := range subMaps {
wg.Add(1)
go func() {
for _, upstream := range sm {
lockCheck.RLock()
isHTTPSfrom := []*ingress.Server{}
for _, server := range servers {
for _, location := range server.Locations {
if upstream.Name == location.Backend {
if len(upstream.Endpoints) == 0 {
glog.V(3).Infof("upstream %v does not have any active endpoints.", upstream.Name)
location.Backend = ""

// check if the location contains endpoints and a custom default backend
if location.DefaultBackend != nil {
sp := location.DefaultBackend.Spec.Ports[0]
endps := n.getEndpoints(location.DefaultBackend, &sp, apiv1.ProtocolTCP, &healthcheck.Config{})
if len(endps) > 0 {
glog.V(3).Infof("using custom default backend in server %v location %v (service %v/%v)",
server.Hostname, location.Path, location.DefaultBackend.Namespace, location.DefaultBackend.Name)
nb := upstream.DeepCopy()
name := fmt.Sprintf("custom-default-backend-%v", upstream.Name)
nb.Name = name
nb.Endpoints = endps
aUpstreams = append(aUpstreams, nb)
location.Backend = name
}
}
}

// Configure Backends[].SSLPassthrough
if server.SSLPassthrough {
if location.Path == rootLocation {
if location.Backend == defUpstreamName {
glog.Warningf("ignoring ssl passthrough of %v as it doesn't have a default backend (root context)", server.Hostname)
continue
}

isHTTPSfrom = append(isHTTPSfrom, server)
}
}
}
}
}
if len(isHTTPSfrom) > 0 {
upstream.SSLPassthrough = true
}
lockCheck.RUnlock()
}
wg.Done()
}()
}

```

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: 1167665ac94e07c04ad868381192090a2b51679b

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.