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

canonical/kubernetes-dqlite: pkg/controller/util/node/controller_utils.go; 23 LoC

Open
#8,901 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 [canonical/kubernetes-dqlite](https://www.github.com/canonical/kubernetes-dqlite) at [pkg/controller/util/node/controller_utils.go](https://github.com/canonical/kubernetes-dqlite/blob/88d4aeadf8ccb0cf95c48c59985bc721e0e14d22/pkg/controller/util/node/controller_utils.go#L133-L155)

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 cond at line 136 may start a goroutine

[Click here to see the code in its original context.](https://github.com/canonical/kubernetes-dqlite/blob/88d4aeadf8ccb0cf95c48c59985bc721e0e14d22/pkg/controller/util/node/controller_utils.go#L133-L155)

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

```go
for _, cond := range pod.Status.Conditions {
if cond.Type == v1.PodReady {
cond.Status = v1.ConditionFalse
if !utilpod.UpdatePodCondition(&pod.Status, &cond) {
break
}

klog.V(2).Infof("Updating ready status of pod %v to false", pod.Name)
_, err := kubeClient.CoreV1().Pods(pod.Namespace).UpdateStatus(context.TODO(), pod, metav1.UpdateOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
// NotFound error means that pod was already deleted.
// There is nothing left to do with this pod.
continue
}
klog.Warningf("Failed to update status for pod %q: %v", format.Pod(pod), err)
errMsg = append(errMsg, fmt.Sprintf("%v", err))
}
// record NodeNotReady event after updateStatus to make sure pod still exists
recorder.Event(pod, v1.EventTypeWarning, "NodeNotReady", "Node is not ready")
break
}
}

```

Click here to show extra information the analyzer produced.

```
The following graphviz dot graph describes paths through the callgraph that could lead to a function calling a goroutine:
digraph G {
"(Update, 3)" -> {"(Accept, 2)";}
"(Handle, 2)" -> {"(Delete, 2)";"(Get, 2)";}
"(roundTrip, 1)" -> {"(awaitOpenSlotForRequest, 1)";}
"(Verifier, 1)" -> {"(newAsyncIDTokenVerifier, 3)";}
"(run, 3)" -> {"(runCmdContext, 2)";}
"(send, 3)" -> {}
"(tryUpgrade, 2)" -> {}
"(newAsyncIDTokenVerifier, 3)" -> {}
"(post, 1)" -> {"(RoundTrip, 1)";}
"(Delete, 2)" -> {"(Accept, 2)";}
"(StartTestServer, 4)" -> {}
"(addEndpoint, 1)" -> {}
"(RoundTrip, 1)" -> {"(roundTrip, 1)";"(RoundTripOpt, 2)";}
"(Insert, 1)" -> {"(Search, 2)";"(Add, 1)";}
"(addConnIfNeeded, 3)" -> {}
"(add, 1)" -> {"(post, 1)";"(newWatchBroadcast, 3)";"(newWatchBroadcasts, 1)";}
"(run, 1)" -> {"(start, 1)";"(send, 3)";}
"(merge, 4)" -> {"(Get, 0)";"(Put, 1)";}
"(fallbackNewRandom, 1)" -> {"(New, 1)";}
"(Do, 3)" -> {"(Copy, 2)";}
"(runCmdContext, 2)" -> {}
"(Txn, 1)" -> {"(Write, 1)";}
"(New, 2)" -> {"(Run, 1)";"(makeNodeDialFunc, 1)";"(add, 1)";"(Start, 1)";"(New, 3)";"(Register, 2)";"(run, 3)";"(migrate, 2)";"(DialFuncWithTLS, 2)";}
"(proxy, 2)" -> {}
"(updatePod, 2)" -> {"(addPod, 1)";"(AddPod, 1)";}
"(newFilePipeline, 3)" -> {}
"(NewClientConn, 3)" -> {"(clientHandshake, 2)";}
"(Put, 1)" -> {"(Update, 3)";}
"(UpdatePodCondition, 2)" -> {"(Equal, 1)";}
"(Start, 1)" -> {"(start, 1)";"(CreateListener, 1)";"(SendRequest, 3)";"(Run, 1)";}
"(Get, 0)" -> {"(Get, 2)";}
"(newAuthenticator, 2)" -> {"(SetTransportDefaults, 1)";}
"(ServeHTTP, 2)" -> {"(serveResource, 6)";"(RoundTrip, 1)";"(tryUpgrade, 2)";"(handleHttps, 2)";"(proxy, 2)";}
"(GetSender, 1)" -> {"(Send, 2)";}
"(UpdatePod, 1)" -> {}
"(proxy, 4)" -> {}
"(Register, 3)" -> {"(startThinPoolWatcher, 1)";"(startZfsWatcher, 1)";}
"(Equal, 1)" -> {"(Get, 1)";"(fallbackNewRandom, 1)";"(Compare, 1)";}
"(List, 2)" -> {"(Accept, 2)";}
"(New, 6)" -> {"(newWatchableStore, 6)";}
"(Search, 2)" -> {"(List, 2)";"(List, 1)";}
"(Start, 2)" -> {}
"(Open, 2)" -> {"(ServeHTTP, 2)";}
"(expand, 2)" -> {"(Write, 1)";}
"(Open, 3)" -> {"(openAtIndex, 4)";}
"(start, 1)" -> {}
"(Accept, 2)" -> {}
"(startZfsWatcher, 1)" -> {}
"(NewWithTLSConfig, 2)" -> {"(SetTransportDefaults, 1)";}
"(StartTestServerOrDie, 4)" -> {"(StartTestServer, 4)";}
"(setDevices, 2)" -> {"(Open, 3)";}
"(newClientTransport, 6)" -> {}
"(CreateListener, 1)" -> {"(ListenPipe, 2)";}
"(SendRequest, 3)" -> {"(send, 3)";}
"(Set, 1)" -> {"(setDevices, 2)";}
"(WaitUntilFreshAndList, 3)" -> {"(waitUntilFreshAndBlock, 2)";}
"(RoundTripOpt, 2)" -> {"(roundTrip, 1)";}
"(get, 1)" -> {"(Run, 1)";"(SetTransportDefaults, 1)";}
"(newClient, 1)" -> {}
"(Read, 1)" -> {"(add, 1)";"(Read, 2)";"(Copy, 2)";"(Write, 1)";}
"(ConfigureTransport, 1)" -> {"(configureTransport, 1)";}
"(configureTransport, 1)" -> {"(addConnIfNeeded, 3)";}
"(awaitOpenSlotForRequest, 1)" -> {}
"(Dial, 3)" -> {"(NewClientConn, 3)";}
"(newWatchBroadcasts, 1)" -> {}
"(ListenPipe, 2)" -> {}
"(DeleteCollection, 4)" -> {}
"(Send, 2)" -> {"(send, 3)";}
"(serveResource, 6)" -> {"(DeleteCollection, 4)";}
"(List, 4)" -> {"(WaitUntilFreshAndList, 3)";}
"(Run, 3)" -> {"(Run, 1)";"(List, 1)";}
"(enableCSM, 3)" -> {"(Start, 2)";}
"(Get, 2)" -> {"(Accept, 2)";}
"(List, 1)" -> {"(List, 4)";}
"(Scan, 1)" -> {"(Set, 1)";}
"(newWatchableStore, 6)" -> {}
"(drainRespBody, 1)" -> {"(Copy, 2)";}
"(Write, 1)" -> {"(Copy, 2)";"(Update, 3)";"(append, 1)";}
"(migrate, 2)" -> {"(Open, 2)";}
"(Run, 1)" -> {"(Register, 2)";"(NewSSHTunnelList, 4)";"(copyToPod, 3)";"(start, 1)";"(Write, 1)";"(run, 1)";"(Update, 2)";}
"(makeNodeDialFunc, 1)" -> {"(proxy, 4)";}
"(Register, 2)" -> {"(addEndpoint, 1)";}
"(Get, 3)" -> {"(drainRespBody, 1)";"(Do, 3)";"(Get, 0)";"(GetSender, 1)";"(Txn, 1)";}
"(dial, 2)" -> {"(dialURL, 3)";}
"(copyToPod, 3)" -> {}
"(Read, 2)" -> {"(Update, 3)";}
"(Update, 2)" -> {"(updatePod, 2)";}
"(openAtIndex, 4)" -> {"(newFilePipeline, 3)";}
"(append, 1)" -> {}
"(ReturnIterator, 1)" -> {"(Put, 1)";}
"(clientHandshake, 2)" -> {"(newClientTransport, 6)";}
"(Get, 1)" -> {"(Search, 2)";"(expand, 2)";"(Put, 1)";"(Get, 0)";"(Read, 1)";"(Get, 3)";"(Scan, 1)";"(Remove, 1)";"(New, 1)";"(Add, 1)";"(get, 1)";"(ReturnIterator, 1)";"(Set, 1)";"(Add, 2)";}
"(New, 1)" -> {"(New, 3)";"(Run, 2)";"(Verifier, 1)";"(enableCSM, 3)";"(Handle, 2)";"(Start, 1)";"(Run, 3)";"(get, 1)";"(newClient, 1)";"(New, 2)";"(Run, 1)";"(New, 6)";"(NewWithTLSConfig, 2)";"(newAuthenticator, 2)";}
"(Copy, 2)" -> {"(ServeHTTP, 2)";}
"(NewSSHTunnelList, 4)" -> {}
"(DialFuncWithTLS, 2)" -> {"(dial, 2)";}
"(newWatchBroadcast, 3)" -> {}
"(handleHttps, 2)" -> {}
"(startThinPoolWatcher, 1)" -> {}
"(New, 3)" -> {"(setup, 1)";"(Register, 2)";"(Open, 2)";}
"(Add, 1)" -> {"(add, 1)";"(Search, 2)";}
"(AddPod, 1)" -> {"(UpdatePod, 1)";}
"(Add, 2)" -> {"(New, 3)";"(Search, 2)";}
"(addPod, 1)" -> {"(AddPod, 1)";}
"(dialURL, 3)" -> {"(Dial, 3)";}
"(Run, 2)" -> {"(CreateControllerContext, 4)";"(Start, 1)";"(Register, 2)";"(run, 1)";"(New, 6)";"(Register, 3)";"(List, 1)";"(Run, 1)";}
"(Compare, 1)" -> {"(merge, 4)";"(Insert, 1)";}
"(Remove, 1)" -> {"(Search, 2)";}
"(CreateControllerContext, 4)" -> {}
"(SetTransportDefaults, 1)" -> {"(ConfigureTransport, 1)";}
"(setup, 1)" -> {"(StartTestServerOrDie, 4)";}
"(waitUntilFreshAndBlock, 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: 88d4aeadf8ccb0cf95c48c59985bc721e0e14d22

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.