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 runnable race in manager #466

Merged
merged 1 commit into from
Jun 6, 2019
Merged

🐛 Fix runnable race in manager #466

merged 1 commit into from
Jun 6, 2019

Conversation

abursavich
Copy link
Contributor

@abursavich abursavich commented Jun 4, 2019

In controllerManager, startLeaderElectionRunnables doesn't protect its read of leaderElectionRunnables and write of started. This may cause a Runnable to be run twice:

  • startNonLeaderElectionRunnables sets started to true
  • Add appends the runnable to leaderElectionRunnables, sees that that started is true, and starts the runnable
  • startLeaderElectionRunnables starts all of the runnables in leaderElectionRunnables

See https://travis-ci.org/kubernetes-sigs/controller-runtime/jobs/541066866 for an example.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 4, 2019
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 4, 2019
@abursavich
Copy link
Contributor Author

I should note that there's another subtle bug with adding leader election runnables, which I noticed when reading this code but this change does not fix.

If a runnable is added after the manager has started, the runnable is unconditionally started. In the case that the runnable should wait for leader election, it will start early (without leadership) and then it will be started again when the manager wins election.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 4, 2019
@DirectXMan12
Copy link
Contributor

Thank you for fixing this. Do you mind also fixing the additional bug you mentioned?

@DirectXMan12
Copy link
Contributor

otherwise looks good. I don't suppose you've found a good way of testing this behavior? races are very hard to test

@abursavich
Copy link
Contributor Author

I would assume that running the existing tests with the race detector would've caught this. Otherwise, no testing ideas.

I can probably get to the other issue in the next few days. I had planned on tackling them separately to keep the diffs smaller and easier to review.

@DirectXMan12
Copy link
Contributor

I can probably get to the other issue in the next few days

Ack. Can you file a separate issue then, just so we don't lose track of it?

I would assume that running the existing tests with the race detector would've caught this

Ah, yeah, need to make sure that's on.

@DirectXMan12
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abursavich, DirectXMan12

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 6, 2019
@k8s-ci-robot k8s-ci-robot merged commit be010e1 into kubernetes-sigs:master Jun 6, 2019
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants