mirror of
https://github.com/kubernetes/client-go.git
synced 2026-06-09 18:55:26 +00:00
client-go/leaderelection: Check context canceled
The change introduced in 59cd1d0b3bb378f40a639e21b615f4df1d4a5a14 causes PollUntilContextTimeout to call the condition function even when the context is canceled already. This is unnecessary in our case and only leads to one extra loop of processing and extra error messages. This change makes the renew loop behave like it did before the change. Kubernetes-commit: aa494f8174d745c3d9842f3d48272a3c2d6dcbcc
This commit is contained in:
committed by
Kubernetes Publisher
parent
764b57d771
commit
8a32b4087c
@@ -283,6 +283,11 @@ func (le *LeaderElector) renew(ctx context.Context) {
|
||||
logger := klog.FromContext(ctx)
|
||||
wait.UntilWithContext(ctx, func(ctx context.Context) {
|
||||
err := wait.PollUntilContextTimeout(ctx, le.config.RetryPeriod, le.config.RenewDeadline, true, func(ctx context.Context) (done bool, err error) {
|
||||
// PollUntilContextTimeout invokes condition even when the context is canceled when immediate=true.
|
||||
// Short-circuit this to prevent unnecessary processing and error log messages.
|
||||
if err := ctx.Err(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !le.config.Coordinated {
|
||||
return le.tryAcquireOrRenew(ctx), nil
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user