-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
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. |
Thank you for fixing this. Do you mind also fixing the additional bug you mentioned? |
otherwise looks good. I don't suppose you've found a good way of testing this behavior? races are very hard to test |
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. |
Ack. Can you file a separate issue then, just so we don't lose track of it?
Ah, yeah, need to make sure that's on. |
/lgtm |
[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 |
In
controllerManager
,startLeaderElectionRunnables
doesn't protect its read ofleaderElectionRunnables
and write ofstarted
. This may cause a Runnable to be run twice:startNonLeaderElectionRunnables
setsstarted
to trueAdd
appends the runnable toleaderElectionRunnables
, sees that thatstarted
is true, and starts the runnablestartLeaderElectionRunnables
starts all of the runnables inleaderElectionRunnables
See https://travis-ci.org/kubernetes-sigs/controller-runtime/jobs/541066866 for an example.