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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 馃悰 Avoid deadlock on start #1689

Conversation

fabriziopandini
Copy link
Member

@fabriziopandini fabriziopandini commented Oct 8, 2021

This PR tries to avoid deadlock in the start sequence when startLeaderElectionRunnables() gets stuck in waitForCache, but the cache can't start due the webhook not yet started, and the webhook with are run in startNonLeaderElectionRunnables() can't run due to to the mutex.

The implementation follow the suggestion in #1685 (comment) and:

  • "Specializes" the current mutex so it prevents Add* functions to be run while the data they collect are being read.
  • Use a read lock for startLeaderElectionRunnables() and startNonLeaderElectionRunnables() and for other serve func thus allowing parallel run
  • Introduces a new look for protecting waitForCache to be executed two times concurrently

Note. Given this is my first PR in this area, I have commented all the reasoning about locks and possible concurrency issues, looking forward for comments.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fabriziopandini
To complete the pull request process, please assign shawn-hurley after the PR has been reviewed.
You can assign the PR to them by writing /assign @shawn-hurley in a comment when ready.

The full list of commands accepted by this bot can be found 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

@@ -535,8 +550,11 @@ func (cm *controllerManager) engageStopProcedure(stopComplete <-chan struct{}) e
if cm.gracefulShutdownTimeout == 0 {
return nil
}
cm.mu.Lock()
defer cm.mu.Unlock()
cm.addMu.RLock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be the WriteLock, because it writes to cm.stopProcedureEngaged.

Also it seems it is not allowed to call waitgroup.Add() during a running waitgroup.Wait() , if I understand the race in CI correctly. Unfortunately you get to debug the locking here now 馃檭

@k8s-ci-robot
Copy link
Contributor

@fabriziopandini: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-test-master 3bdf1ad link true /test pull-controller-runtime-test-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@fabriziopandini
Copy link
Member Author

If there are no objections, I would close this PR in favour of #1690
which seem much more simpler (thus reducing risk for back porting)

@fabriziopandini
Copy link
Member Author

/close

@k8s-ci-robot
Copy link
Contributor

@fabriziopandini: Closed this PR.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@fabriziopandini fabriziopandini deleted the avoid-deadlock-during-start branch November 2, 2021 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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.

None yet

3 participants