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

k8snetworkplumbingwg/kubemacpool: pkg/pool-manager/pod_pool.go; 44 LoC

Open
#8,089 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 [k8snetworkplumbingwg/kubemacpool](https://www.github.com/k8snetworkplumbingwg/kubemacpool) at [pkg/pool-manager/pod_pool.go](https://github.com/k8snetworkplumbingwg/kubemacpool/blob/68c40766b8966e2e3e149da2bee5ff55dfc8a6c2/pkg/pool-manager/pod_pool.go#L202-L245)

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 pod at line 224 may start a goroutine

[Click here to see the code in its original context.](https://github.com/k8snetworkplumbingwg/kubemacpool/blob/68c40766b8966e2e3e149da2bee5ff55dfc8a6c2/pkg/pool-manager/pod_pool.go#L202-L245)

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

```go
for _, pod := range pods.Items {
log.V(1).Info("InitMaps for pod", "podName", pod.Name, "podNamespace", pod.Namespace)
if pod.Annotations == nil {
continue
}

networkValue, ok := pod.Annotations[networksAnnotation]
if !ok {
continue
}

networks, err := parsePodNetworkAnnotation(networkValue, pod.Namespace)
if err != nil {
continue
}

log.V(1).Info("pod meta data", "podMetaData", pod.ObjectMeta)
if len(networks) == 0 {
continue
}

// validate if the pod is related to kubevirt
if p.isRelatedToKubevirt(&pod) {
// nothing to do here. the mac is already by allocated by the virtual machine webhook
log.V(1).Info("This pod have ownerReferences from kubevirt skipping")
continue
}

for _, network := range networks {
if network.MacRequest == "" {
continue
}

if err := p.allocatePodRequestedMac(network, &pod); err != nil {
// Dont return an error here if we can't allocate a mac for a running pod
log.Error(fmt.Errorf("failed to parse mac address for pod"),
"Invalid mac address for pod",
"namespace", pod.Namespace,
"name", pod.Name,
"mac", network.MacRequest)
continue
}
}
}

```

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 {
"(string, 1)" -> {"(uint64, 1)";"(marker, 1)";"(tracef, 2)";"(int64, 1)";}
"(Sub, 1)" -> {"(AsDec, 0)";}
"(Scan, 0)" -> {"(New, 0)";"(init, 0)";"(Write, 1)";}
"(close, 1)" -> {"(Delete, 1)";}
"(output, 6)" -> {"(timeoutFlush, 1)";}
"(Now, 0)" -> {"(Add, 1)";}
"(, 1)" -> {"(Write, 1)";"(Start, 0)";"(init, 0)";"(Decode, 2)";"(RecognizesData, 1)";"(printf, 4)";"(getDelegate, 0)";}
"(AfterFunc, 2)" -> {"(removeChild, 2)";}
"(AddHelp, 2)" -> {}
"(AddPackage, 1)" -> {"(indexTypes, 1)";}
"(IsValid, 0)" -> {"(asyncFlush, 1)";"(runSample, 2)";"(acquire, 1)";"(renew, 1)";"(NewNamedRateLimitingQueue, 2)";"(ListAndWatch, 1)";"(WithCancel, 1)";"(get, 2)";"(New, 0)";"(ConfigureTransport, 1)";"(Write, 1)";"(processPkg, 2)";"(Transform, 3)";"(StartWithChannel, 2)";"(Read, 1)";"(Run, 0)";"(Get, 3)";"(PollImmediateUntil, 3)";}
"(cancel, 2)" -> {}
"(get, 2)" -> {"(fnv32a, 1)";}
"(WriteFile, 2)" -> {"(WriteFile, 3)";}
"(Watch, 2)" -> {"(NewRaceFreeFake, 0)";}
"(itag, 1)" -> {"(insertFlush, 3)";}
"(NewDiscoveryClientForConfig, 1)" -> {"(UnversionedRESTClientFor, 1)";}
"(NewGenerationBehavior, 1)" -> {"(Raw, 1)";}
"(processPkg, 2)" -> {}
"(run, 0)" -> {"(close, 1)";}
"(Rename, 2)" -> {}
"(Kqueue, 0)" -> {}
"(EachType, 3)" -> {"(cb, 1)";}
"(getDelegate, 0)" -> {"(NewDiscoveryRESTMapper, 1)";}
"(check, 1)" -> {"(NeedTypesInfo, 0)";}
"(WithCancel, 1)" -> {"(cancel, 2)";}
"(newDelayingQueue, 3)" -> {}
"(Parse, 1)" -> {"(Scan, 0)";}
"(Shutdown, 1)" -> {"(shutdownEnterWaitStateHook, 0)";}
"(Gather, 0)" -> {"(checkMetricConsistency, 3)";}
"(fetchGroupVersionResources, 2)" -> {}
"(updateIndices, 3)" -> {"(indexFunc, 1)";}
"(startRunnable, 1)" -> {"(Start, 1)";}
"(Error, 0)" -> {"(, 1)";}
"(Read, 1)" -> {}
"(PrintErrors, 2)" -> {"(Visit, 3)";}
"(Start, 3)" -> {"(f, 3)";}
"(Serve, 1)" -> {"(shutdownEnterWaitStateHook, 0)";}
"(WriteFile, 3)" -> {"(Rename, 2)";}
"(get, 1)" -> {"(IsValid, 0)";}
"(uint64, 1)" -> {"(Write, 1)";}
"(ListAndWatch, 1)" -> {"(Warningf, 4)";}
"(NewWatcher, 0)" -> {"(kqueue, 0)";}
"(Delete, 1)" -> {"(Remove, 2)";}
"(Clear, 0)" -> {}
"(NewBroadcaster, 2)" -> {}
"(newClientConn, 2)" -> {}
"(NewChecker, 4)" -> {}
"(WithDeadline, 2)" -> {"(AfterFunc, 2)";}
"(kind, 0)" -> {"(itag, 1)";}
"(runRaw, 2)" -> {"(Error, 3)";}
"(HasPrefix, 1)" -> {"(IsDir, 1)";}
"(Quo, 2)" -> {}
"(IsLeader, 0)" -> {"(WaitFor, 3)";}
"(Done, 0)" -> {}
"(printf, 4)" -> {"(output, 6)";}
"(removeChild, 2)" -> {}
"(format, 0)" -> {"(packageLevelValue, 1)";}
"(ReadCertificate, 0)" -> {"(LoadX509KeyPair, 2)";}
"(runCmdContext, 2)" -> {"(Kill, 0)";}
"(timeoutFlush, 1)" -> {}
"(IsDir, 1)" -> {}
"(StartInterceptingOutput, 0)" -> {"(TailFile, 2)";}
"(ServerGroupsAndResources, 1)" -> {"(fetchGroupVersionResources, 2)";}
"(printWithFileLine, 6)" -> {"(output, 6)";}
"(NewRaceFreeFake, 0)" -> {"(ExtractFromListOptions, 1)";}
"(isTextResponse, 1)" -> {"(init, 0)";"(Get, 3)";"(printf, 4)";"(get, 2)";"(Add, 2)";"(New, 1)";}
"(Get, 3)" -> {"(resource, 0)";}
"(resource, 0)" -> {}
"(DecodeRaw, 2)" -> {}
"(configureTransport, 1)" -> {"(addConnIfNeeded, 3)";}
"(setProvider, 1)" -> {}
"(kqueue, 0)" -> {"(Kqueue, 0)";"(NewBroadcaster, 2)";}
"(Get, 1)" -> {"(GetUsing, 2)";}
"(setBytes, 1)" -> {"(Walk, 2)";}
"(add, 2)" -> {"(Watch, 3)";}
"(New, 0)" -> {"(newOne, 0)";}
"(LoadX509KeyPair, 2)" -> {"(NewBroadcaster, 2)";}
"(NewClientConn, 1)" -> {"(newClientConn, 2)";}
"(ChangeEvents, 2)" -> {}
"(acquire, 1)" -> {"(Done, 0)";}
"(CodeLocation, 0)" -> {"(Visit, 3)";}
"(init, 0)" -> {"(makeStringToBuiltinPluginTypeMap, 0)";"(VendorEnabled, 3)";"(Register, 1)";}
"(sweetenFields, 1)" -> {"(check, 1)";"(get, 2)";"(WriteTo, 1)";"(printWithFileLine, 6)";}
"(transformResponse, 2)" -> {"(isTextResponse, 1)";}
"(Observe, 1)" -> {"(asyncFlush, 1)";}
"(RecognizesData, 1)" -> {"(NewReaderSize, 2)";}
"(announceSubject, 2)" -> {"(CodeLocation, 0)";}
"(PollImmediateUntil, 3)" -> {"(PollUntil, 3)";}
"(shutdownEnterWaitStateHook, 0)" -> {"(Gather, 0)";}
"(onEvict, 2)" -> {}
"(insertFlush, 3)" -> {"(Walk, 2)";}
"(indexTypes, 1)" -> {"(EachType, 3)";}
"(String, 0)" -> {"(reorderOutput, 1)";"(Write, 1)";"(Start, 0)";"(getDelegate, 0)";}
"(Decode, 2)" -> {"(DecodeRaw, 2)";}
"(ConfigureTransport, 1)" -> {"(configureTransport, 1)";}
"(Terminate, 0)" -> {}
"(typeCheck, 1)" -> {"(NewChecker, 4)";}
"(decomposeSegment, 3)" -> {"(insertFlush, 3)";}
"(AsDec, 0)" -> {"(startRunnable, 1)";"(Write, 1)";"(add, 2)";"(New, 1)";"(Add, 2)";}
"(tracef, 2)" -> {"(String, 0)";}
"(makeStringToBuiltinPluginTypeMap, 0)" -> {"(setProvider, 1)";}
"(NeedTypesInfo, 0)" -> {"(typeCheck, 1)";}
"(New, 1)" -> {"(newLoaderAtConfirmedDir, 5)";}
"(Watch, 3)" -> {"(Start, 3)";}
"(newLoaderAtConfirmedDir, 5)" -> {"(HasPrefix, 1)";}
"(request, 2)" -> {"(Duration, 1)";}
"(Add, 1)" -> {"(Add, 2)";"(startRunnable, 1)";"(add, 2)";"(New, 1)";}
"(int, 1)" -> {"(int64, 1)";}
"(Run, 0)" -> {"(PrintErrors, 2)";}
"(NewSchemeBuilder, 1)" -> {"(Register, 1)";}
"(Transform, 3)" -> {"(kind, 0)";"(elem, 1)";}
"(Walk, 2)" -> {}
"(NewDiscoveryRESTMapper, 1)" -> {"(NewDiscoveryClientForConfig, 1)";}
"(tailFileSync, 0)" -> {"(waitForChanges, 0)";}
"(addConnIfNeeded, 3)" -> {"(run, 3)";}
"(Unset, 0)" -> {"(format, 0)";}
"(WaitFor, 3)" -> {}
"(ExtractFromListOptions, 1)" -> {}
"(NewNamedDelayingQueue, 1)" -> {"(NewDelayingQueueWithCustomClock, 2)";}
"(Info, 1)" -> {"(log, 4)";"(print, 3)";}
"(log, 4)" -> {"(sweetenFields, 1)";}
"(asyncFlush, 1)" -> {}
"(VendorEnabled, 3)" -> {"(Run, 2)";}
"(f, 3)" -> {}
"(NewSimpleClientset, 1)" -> {"(Watch, 2)";}
"(post, 1)" -> {"(StartInterceptingOutput, 0)";"(TailFile, 2)";}
"(Duration, 1)" -> {"(NewSimpleClientset, 1)";"(Get, 1)";"(AddPackage, 1)";"(printf, 4)";"(Add, 2)";"(NewError, 2)";"(String, 0)";"(Write, 1)";"(New, 2)";"(NewTestClient, 0)";"(NewSchemeBuilder, 1)";"(Observe, 1)";"(getDelegate, 0)";"(Start, 0)";"(Get, 3)";"(run, 0)";"(New, 1)";"(WithDeadline, 2)";"(Transform, 3)";"(NewUnboundedExecutor, 0)";}
"(Wait, 0)" -> {"(init, 0)";}
"(elem, 1)" -> {"(decomposeSegment, 3)";"(init, 2)";}
"(allocate, 0)" -> {}
"(Error, 3)" -> {"(run, 3)";}
"(Start, 2)" -> {"(Terminate, 0)";"(Start, 3)";}
"(print, 3)" -> {"(printDepth, 4)";}
"(UnversionedRESTClientFor, 1)" -> {"(fetchGroupVersionResources, 2)";}
"(checkMetricConsistency, 3)" -> {}
"(Do, 1)" -> {"(Now, 0)";"(Sub, 1)";"(transformResponse, 2)";"(request, 2)";}
"(newOne, 0)" -> {"(Clear, 0)";}
"(WriteTo, 1)" -> {"(Unset, 0)";}
"(NewDelayingQueueWithCustomClock, 2)" -> {"(newDelayingQueue, 3)";}
"(Raw, 1)" -> {"(ServerGroupsAndResources, 1)";}
"(cb, 1)" -> {"(Walk, 2)";}
"(Get, 0)" -> {"(Wait, 0)";"(int, 1)";"(Error, 0)";"(Decode, 3)";"(get, 1)";}
"(Start, 0)" -> {"(Start, 2)";}
"(release, 0)" -> {"(IsLeader, 0)";}
"(unwrapRecursively, 0)" -> {}
"(Add, 2)" -> {"(updateIndices, 3)";}
"(init, 2)" -> {"(setBytes, 1)";}
"(Write, 1)" -> {"(Transform, 3)";"(WriteTo, 1)";"(printWithFileLine, 6)";"(WriteFile, 2)";}
"(runSample, 2)" -> {"(announceSubject, 2)";}
"(Update, 1)" -> {}
"(NewNamedRateLimitingQueue, 2)" -> {"(NewNamedDelayingQueue, 1)";}
"(Kill, 0)" -> {}
"(packageLevelValue, 1)" -> {}
"(NewError, 2)" -> {"(New, 2)";}
"(isRelatedToKubevirt, 1)" -> {"(Info, 1)";"(RequestURI, 1)";"(Get, 0)";"(Do, 1)";"(string, 1)";}
"(Register, 1)" -> {"(AddHelp, 2)";"(unwrapRecursively, 0)";}
"(printDepth, 4)" -> {"(output, 6)";}
"(NewUnboundedExecutor, 0)" -> {"(WithCancel, 1)";}
"(GetUsing, 2)" -> {"(allocValueUnstructured, 0)";}
"(Visit, 3)" -> {"(post, 1)";"(StartInterceptingOutput, 0)";}
"(PollUntil, 3)" -> {"(poller, 2)";}
"(indexFunc, 1)" -> {"(Quo, 2)";"(onEvict, 2)";"(newQueueMetrics, 2)";}
"(Decode, 3)" -> {"(ConvertToVersion, 2)";}
"(marker, 1)" -> {"(errorf, 3)";}
"(errorf, 3)" -> {"(Write, 1)";}
"(Run, 2)" -> {"(runRaw, 2)";}
"(fnv32a, 1)" -> {"(poller, 2)";}
"(poller, 2)" -> {}
"(allocValueUnstructured, 0)" -> {"(allocate, 0)";}
"(run, 3)" -> {"(runCmdContext, 2)";"(NewClientConn, 1)";}
"(int64, 1)" -> {"(Write, 1)";}
"(Start, 1)" -> {"(Serve, 1)";"(Shutdown, 1)";}
"(New, 2)" -> {"(NewWatcher, 0)";"(ReadCertificate, 0)";}
"(Warningf, 4)" -> {"(Update, 1)";}
"(reorderOutput, 1)" -> {"(NewGenerationBehavior, 1)";}
"(waitForChanges, 0)" -> {"(ChangeEvents, 2)";}
"(ConvertToVersion, 2)" -> {"(Read, 1)";"(New, 0)";}
"(Remove, 2)" -> {}
"(StartWithChannel, 2)" -> {"(Start, 1)";}
"(renew, 1)" -> {"(release, 0)";}
"(newQueueMetrics, 2)" -> {}
"(TailFile, 2)" -> {"(tailFileSync, 0)";}
"(RequestURI, 1)" -> {"(Parse, 1)";}
"(NewReaderSize, 2)" -> {}
"(NewTestClient, 0)" -> {"(New, 2)";}
}

```

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: 68c40766b8966e2e3e149da2bee5ff55dfc8a6c2

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.