Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a problem with for loops, copy semantics and async routines. #1616

Merged
merged 1 commit into from
Oct 7, 2014

Conversation

brendandburns
Copy link
Contributor

@proppy @bgrant0607 Fixes a bug introduced by f91162c#diff-bf28da68f62a8df6e99e447c4351122dR637

Go lang for loop copy semantics and async routines are not friends.

@thockin
Copy link
Member

thockin commented Oct 7, 2014

Oh, Go. You love your little landmines.

@thockin
Copy link
Member

thockin commented Oct 7, 2014

LGTM is what I meant to say.

@brendandburns
Copy link
Contributor Author

Merging, since this is clearly a bug, and I think it's what's breaking e2e too.

brendandburns added a commit that referenced this pull request Oct 7, 2014
Fix a problem with for loops, copy semantics and async routines.
@brendandburns brendandburns merged commit b2dd4ac into kubernetes:master Oct 7, 2014
@proppy
Copy link
Contributor

proppy commented Oct 7, 2014

oh nice find, at first I didn't catch the extra copy.

@brendandburns
Copy link
Contributor Author

It's not the extra copy, it's that the pointer is to the loop variable
which keeps getting copied over.

On Tue, Oct 7, 2014 at 9:24 AM, Johan Euphrosine notifications@github.com
wrote:

oh nice find, at first I didn't catch the extra copy.


Reply to this email directly or view it on GitHub
#1616 (comment)
.

@proppy
Copy link
Contributor

proppy commented Oct 7, 2014

@brendanburns oh right, I also didn't catch we were passing a pointer to the loop variable.

@lavalamp
Copy link
Member

lavalamp commented Oct 7, 2014

Good fix. How did this get in in the first place? If a reviewer just missed it, that's fine, it happens--but everyone needs to be aware of this class of problem.

@proppy
Copy link
Contributor

proppy commented Oct 7, 2014

@lavalamp, I think it wasn't caught during review because it was mixed with another "medium" change.
#1534

The last travis build for this change was passing, so I'm not sure if this area is covered:
https://travis-ci.org/GoogleCloudPlatform/kubernetes/builds/37019788

@thockin
Copy link
Member

thockin commented Oct 7, 2014

Does go vet or some other linter warn for this? This is EXACTLY what tools
should be warning on. And copying mutexes. And shadowing variables.

On Tue, Oct 7, 2014 at 10:37 AM, Daniel Smith notifications@github.com
wrote:

Good fix. How did this get in in the first place? If a reviewer just
missed it, that's fine, it happens--but everyone needs to be aware of this
class of problem.

Reply to this email directly or view it on GitHub
#1616 (comment)
.

@proppy
Copy link
Contributor

proppy commented Oct 7, 2014

@thockin sounds like good contributions to go vet, but that doesn't really excuse my silly programming mistake :)

@thockin
Copy link
Member

thockin commented Oct 7, 2014

But it's not you - I've done this. I've seen it listed as a known landmine
on golang forums.

On Tue, Oct 7, 2014 at 10:48 AM, Johan Euphrosine notifications@github.com
wrote:

@thockin https://github.com/thockin sounds like good contributions to go
vet, but that doesn't really excuse my silly programming mistake :)

Reply to this email directly or view it on GitHub
#1616 (comment)
.

@proppy
Copy link
Contributor

proppy commented Oct 7, 2014

Something else to note is that it is sometime "hard" to detect when you're calling into async code (no excuse here because of the // comment and the podWorkers), that's something to keep in mind for the rest of the codebase and maybe adopt a convention to suffix async function, or make them sync by default and leave it to the caller to wrap them with a goroutine.

@bgrant0607
Copy link
Member

Honestly, many of us are Go newbies (myself included), so it's not surprising that this was missed in review.

@brendandburns
Copy link
Contributor Author

Or just never use for _, ix { ... } semantics. It's both slower and error
prone, there's not much win there.

--brendan

On Tue, Oct 7, 2014 at 12:41 PM, bgrant0607 notifications@github.com
wrote:

Honestly, many of us are Go newbies (myself included), so it's not
surprising that this was missed in review.


Reply to this email directly or view it on GitHub
#1616 (comment)
.

@lavalamp
Copy link
Member

lavalamp commented Oct 7, 2014

It's legit when looping through a list/map of pointers and not saving
references to the index variable. Other than that, I agree that it's
suboptimal or outright buggy.

On Tue, Oct 7, 2014 at 12:53 PM, Brendan Burns notifications@github.com
wrote:

Or just never use for _, ix { ... } semantics. It's both slower and error
prone, there's not much win there.

--brendan

On Tue, Oct 7, 2014 at 12:41 PM, bgrant0607 notifications@github.com
wrote:

Honestly, many of us are Go newbies (myself included), so it's not
surprising that this was missed in review.


Reply to this email directly or view it on GitHub
<
https://github.com/GoogleCloudPlatform/kubernetes/pull/1616#issuecomment-58247499>

.


Reply to this email directly or view it on GitHub
#1616 (comment)
.

@brendandburns
Copy link
Contributor Author

Yeah, that's true, but it's a hard enough rule to keep in my head (esp.
when a type might be a map under a typedef) that I prefer the cleaner rule
(esp. as a reviewer)

On Tue, Oct 7, 2014 at 12:56 PM, Daniel Smith notifications@github.com
wrote:

It's legit when looping through a list/map of pointers and not saving
references to the index variable. Other than that, I agree that it's
suboptimal or outright buggy.

On Tue, Oct 7, 2014 at 12:53 PM, Brendan Burns notifications@github.com
wrote:

Or just never use for _, ix { ... } semantics. It's both slower and
error
prone, there's not much win there.

--brendan

On Tue, Oct 7, 2014 at 12:41 PM, bgrant0607 notifications@github.com
wrote:

Honestly, many of us are Go newbies (myself included), so it's not
surprising that this was missed in review.


Reply to this email directly or view it on GitHub
<

https://github.com/GoogleCloudPlatform/kubernetes/pull/1616#issuecomment-58247499>

.


Reply to this email directly or view it on GitHub
<
https://github.com/GoogleCloudPlatform/kubernetes/pull/1616#issuecomment-58249636>

.


Reply to this email directly or view it on GitHub
#1616 (comment)
.

bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Jun 27, 2023
UPSTREAM: <carry>: when only this kube-apiserver can fulfill the kube…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants