-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix (Flux)HelmRelease cluster lookups #2018
Conversation
The value obtained by `_, value := range slice` is overwritten on every iteration. Thus, saving a pointer to `value` is dangerous since its content will be overwritten in the next iteration. From https://golang.org/ref/spec#For_range : > For each entry it assigns iteration values to corresponding > iteration variables if present and then executes the block. But the iteration variables are the same on each iteration. More explicitly, from [the gccgo source code](https://github.com/golang/gofrontend/blob/e387439bfd24d5e142874b8e68e7039f74c744d7/go/statements.cc#L5593-L5604): ``` // The loop we generate: // len_temp := len(range) // range_temp := range // for index_temp = 0; index_temp < len_temp; index_temp++ { // value_temp = range_temp[index_temp] // index = index_temp // value = value_temp // original body // } ```
815b94b
to
7183f13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Fons 👑
Fix looks good to go to me (and looking for this must have been fun).
I am now wondering if we do this in other places though, guess it is a matter of time before we find out.
It didn't take that long, I had a similar problem in #1848 and went directly to the loop.
I checked the other resources and are ok. I wonder if |
I agree that using the address of a loopvar is often going to lead to problems. Can you explain what was the problem in this specific case? It looks to me like the |
Ah, the intermediate |
Looks like this did not fix the issue described in #2011. Output from $ fluxctl list-workloads
WORKLOAD CONTAINER IMAGE RELEASE POLICY
<snip>
default:helmrelease/faulty2
default:helmrelease/faulty2
$ kubectl get helmrelease
NAME AGE
faulty 5d21h
faulty2 5d19h |
Interesting, I did test the fix and |
Exactly, I should probably had explained that instead of elaborating on why you should save a pointer to a loop variable. |
I had a look at some |
@2opremio see below
|
@hiddeco can you triple-check that you are running the image from master? |
@2opremio err, crap, you are right, my image was fixed on something else. Nevermind. |
No worries, it happens. Thanks for checking that the fix works! |
Fixes #2011 (Introduced in #1111)
The value obtained by
_, value := range slice
is overwritten on every iteration. Thus, saving a pointer tovalue
is dangerous since its content will be overwritten in the next iteration.From https://golang.org/ref/spec#For_range :
But the iteration variables are the same on each iteration.
More explicitly, from the gccgo source code: