🐛 manager: suppress expected leader-election-lost error on graceful shutdown - #3536
🐛 manager: suppress expected leader-election-lost error on graceful shutdown#3536liketosweep wants to merge 2 commits into
Conversation
|
Welcome @liketosweep! |
|
Hi @liketosweep. 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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liketosweep The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| select { | ||
| case err := <-cm.errChan: | ||
| if !errors.Is(err, context.Canceled) { | ||
| if !errors.Is(err, context.Canceled) && !errors.Is(err, errLeaderElectionLost) { |
There was a problem hiding this comment.
This means we will not emit an error anymore even if we lost leader election for a reason other than having stopped the binary which would be wrong?
There was a problem hiding this comment.
The two errChan readers are sequential, not concurrent. engageStopProcedure is called via defer in Start() (line 386), so this drain goroutine only starts after Start()'s select loop has already exited consuming and returning any mid-run errLeaderElectionLost to the caller. Any instance seen here was caused by our own internalCancel(). I've added a comment in the latest commit to make this explicit.
There was a problem hiding this comment.
I think it was a valid point on the issue that this Go routine should be completed before we return from engageStopProcedure.
Otherwise if we get any other error here and then log to cm.logger we would have the same problem again.
Signed-off-by: liketosweep <liketosweep@gmail.com>
|
/ok-to-test |
Fixes #3535
What the Issue Was
On graceful shutdown with
LeaderElectionenabled, cancelling theleader election context triggers
OnStoppedLeading, which pusheserrLeaderElectionLostontoerrChan. The drain goroutine inengageStopProcedureonly filteredcontext.Canceled, so thisexpected error was logged as unexpected:
When combined with
t.Output()in tests, this also causes panics ordata races as the manager writes to the test log after the test exits.
Solution
errLeaderElectionLostsentinel for reliableerrors.Ismatching.OnStoppedLeadinginstead of an anonymouserrors.New.engageStopProceduredrain filteralongside
context.Canceled.Genuine mid-run leader election loss (before stop is engaged) still
propagates to
Start's caller unchanged.Changes
pkg/manager/internal.go: sentinel + filter fix.pkg/manager/manager_test.go: regression test for graceful shutdown.Testing