Commit 52d87de1 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents 75115b08 d3b935a4
......@@ -128,7 +128,9 @@ func (r *rudimentaryErrorBackoff) OnError(error) {
r.lastErrorTimeLock.Lock()
defer r.lastErrorTimeLock.Unlock()
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)
}
r.lastErrorTime = time.Now()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment