This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backoff controller has two issues: 1) backoff() can overflow the exponent value leading to 0 backoff duration all the time. 2) There is a race condition in updating fields of the simple backoff handler. this PR should address both.
- Loading branch information
Showing
5 changed files
with
94 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package backoff | ||
|
||
import ( | ||
"sync/atomic" | ||
"time" | ||
) | ||
|
||
// AtomicTime represents an atomic.Value that stores time.Time. | ||
type AtomicTime struct { | ||
v atomic.Value | ||
} | ||
|
||
// Loads the underlying time.Time. | ||
func (a *AtomicTime) Load() time.Time { | ||
return a.v.Load().(time.Time) | ||
} | ||
|
||
// Stores time.Time to the underlying atomic.Value | ||
func (a *AtomicTime) Store(t time.Time) { | ||
a.v.Store(t) | ||
} | ||
|
||
// Creates a new Atomic time.Time | ||
func NewAtomicTime(t time.Time) AtomicTime { | ||
v := atomic.Value{} | ||
v.Store(t) | ||
|
||
return AtomicTime{ | ||
v: v, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters