-
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 bug when set renewDeadline greater than leaseDuration the controlā¦ #1761
Conversation
|
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). š Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. |
Welcome @yuzp1996! |
Hi @yuzp1996. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yuzp1996 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 |
pkg/manager/internal.go
Outdated
@@ -634,6 +634,7 @@ func (cm *controllerManager) startLeaderElection(ctx context.Context) (err error | |||
ReleaseOnCancel: cm.leaderElectionReleaseOnCancel, | |||
}) | |||
if err != nil { |
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.
if err happend the leaderElectionStopped will not close and engageStopProcedure will hang in this code
defer func() {
// Cancel leader election only after we waited. It will os.Exit() the app for safety.
if cm.resourceLock != nil {
// After asking the context to be cancelled, make sure
// we wait for the leader stopped channel to be closed, otherwise
// we might encounter race conditions between this code
// and the event recorder, which is used within leader election code.
cm.leaderElectionCancel()
<-cm.leaderElectionStopped
}
}()
so I think when error happened we should close this channel
@yuzp1996 Yeah, it is a bug here, but not only for the NewLeaderElector error. The cause of the manager hang during stopping, is the
So it might need to change like this, IMHO
|
@@ -637,6 +638,10 @@ func (cm *controllerManager) startLeaderElection(ctx context.Context) (err error | |||
return err | |||
} | |||
|
|||
ctx, cancel := context.WithCancel(context.Background()) |
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.
Following @FillZpp's suggestion, I changed the location of initialization cm.leaderElectionCancel
and cm.leaderElectionStopped
. So these values āāwill not be nil if NewLeaderElector
succeeds.
When engageStopProcedure
needs to check cm.leaderElectionCancel
and cm.leaderElectionStopped
, it will first check whether they are nil.
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.
I'm not sure if this is correct, if we set the context and cancel here it'll be set in a goroutine which can cause a race condition if the controller closes too quickly.
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.
Mostly LG. Some nits.
/ok-to-test
// we wait for the leader stopped channel to be closed, otherwise | ||
// we might encounter race conditions between this code | ||
// and the event recorder, which is used within leader election code. | ||
if cm.leaderElectionCancel != nil { |
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.
It seems you only have to check one of cm.leaderElectionCancel
and cm.leaderElectionStopped
for now they are assigned at the same place.
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.
Yes but I think maybe checking them individually is safer š
@yuzp1996 And you have to fix the failed job, which you can test locally with |
ā¦ler will hang and no error will be return but actually the error should be throw and exit Signed-off-by: yuzhipeng <[email protected]>
Thanks for fixing this. |
@FillZpp: GitHub didn't allow me to request PR reviews from the following users: PTAL. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
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. |
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.
Why do you want renewDeadline greater than lease duration? The lease should always be greater than its renewal, otherwise you might end up losing leader election which is probably what's happening here.
We could validate that the rule above applies and enforce it when configuring the manager, instead of changing the code around to avoid leader election.
/hold
Yes, I think we have had the validation but when someone set renewDeadline greater than lease duration the whole process will block and does not throw an error. I don't think this is the correct way to do that so I make some changes to make sure errors can be thrown |
@vincepri As I said above, it is not only caused by renewDeadline greater than lease duration. Any error occurred between
They will all return error, trigger |
WDYT @vincepri |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
Can we add a failing test that covers the above bug first which can help explain and prevent the deadlock above? I cannot reproduce locally, so it'd be good to have a test for this |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
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. |
fix bug when set renewDeadline greater than leaseDuration the controller will hang and no error will be return
Issue: #1760