fix: Hang when canceling leader election information

Hang when canceling leader election information.
Occasionally, two leaders may run simultaneously.
This commit is contained in:
jiuker 2024-04-28 15:06:51 +08:00 committed by GitHub
parent 62ced20cdc
commit b6b46a0e00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -304,7 +304,9 @@ func (le *LeaderElector) release() bool {
RenewTime: now,
AcquireTime: now,
}
if err := le.config.Lock.Update(context.TODO(), leaderElectionRecord); err != nil {
timeoutCtx, timeoutCancel := context.WithTimeout(context.Background(), le.config.RenewDeadline)
defer timeoutCancel()
if err := le.config.Lock.Update(timeoutCtx, leaderElectionRecord); err != nil {
klog.Errorf("Failed to release lock: %v", err)
return false
}