mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #54237 from lichuqiang/apimachinery_fix
Automatic merge from submit-queue (batch tested with PRs 52717, 54568, 54452, 53997, 54237). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix bug in func OnError() of apimachinery in case time moves backwards for any reason **What this PR does / why we need it**: in func OnError() of ErrorHandlers in apimachinery ``` func (r *rudimentaryErrorBackoff) OnError(error) { r.lastErrorTimeLock.Lock() defer r.lastErrorTimeLock.Unlock() d := time.Since(r.lastErrorTime) if d < 0 { time.Sleep(r.minPeriod - d) } r.lastErrorTime = time.Now() } ``` it is expected to go on sleep for some time if not meet the minPeriod. However, if time happens hops to the past in the process. `d := time.Since(r.lastErrorTime)` would be a negative number, thus, it may sleep a lot longer than we expected. The period for sleep should be reseted if time hops **Which issue this PR fixes** fixes #54236 **Release note**: ```release-note NONE ```
This commit is contained in:
commit
52d87de107
@ -128,7 +128,9 @@ func (r *rudimentaryErrorBackoff) OnError(error) {
|
|||||||
r.lastErrorTimeLock.Lock()
|
r.lastErrorTimeLock.Lock()
|
||||||
defer r.lastErrorTimeLock.Unlock()
|
defer r.lastErrorTimeLock.Unlock()
|
||||||
d := time.Since(r.lastErrorTime)
|
d := time.Since(r.lastErrorTime)
|
||||||
if d < r.minPeriod {
|
if d < r.minPeriod && d >= 0 {
|
||||||
|
// If the time moves backwards for any reason, do nothing
|
||||||
|
// TODO: remove check "d >= 0" after go 1.8 is no longer supported
|
||||||
time.Sleep(r.minPeriod - d)
|
time.Sleep(r.minPeriod - d)
|
||||||
}
|
}
|
||||||
r.lastErrorTime = time.Now()
|
r.lastErrorTime = time.Now()
|
||||||
|
Loading…
Reference in New Issue
Block a user