diff -Nru golang-github-cenkalti-backoff-2.0.0/context.go golang-github-cenkalti-backoff-3.1.1/context.go --- golang-github-cenkalti-backoff-2.0.0/context.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/context.go 2019-11-23 10:56:18.000000000 +0000 @@ -1,14 +1,13 @@ package backoff import ( + "context" "time" - - "golang.org/x/net/context" ) // BackOffContext is a backoff policy that stops retrying after the context // is canceled. -type BackOffContext interface { +type BackOffContext interface { // nolint: golint BackOff Context() context.Context } @@ -21,7 +20,7 @@ // WithContext returns a BackOffContext with context ctx // // ctx must not be nil -func WithContext(b BackOff, ctx context.Context) BackOffContext { +func WithContext(b BackOff, ctx context.Context) BackOffContext { // nolint: golint if ctx == nil { panic("nil context") } @@ -52,9 +51,13 @@ func (b *backOffContext) NextBackOff() time.Duration { select { - case <-b.Context().Done(): + case <-b.ctx.Done(): return Stop default: - return b.BackOff.NextBackOff() } + next := b.BackOff.NextBackOff() + if deadline, ok := b.ctx.Deadline(); ok && deadline.Sub(time.Now()) < next { // nolint: gosimple + return Stop + } + return next } diff -Nru golang-github-cenkalti-backoff-2.0.0/context_test.go golang-github-cenkalti-backoff-3.1.1/context_test.go --- golang-github-cenkalti-backoff-2.0.0/context_test.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/context_test.go 2019-11-23 10:56:18.000000000 +0000 @@ -1,10 +1,9 @@ package backoff import ( + "context" "testing" "time" - - "golang.org/x/net/context" ) func TestContext(t *testing.T) { diff -Nru golang-github-cenkalti-backoff-2.0.0/debian/changelog golang-github-cenkalti-backoff-3.1.1/debian/changelog --- golang-github-cenkalti-backoff-2.0.0/debian/changelog 2019-09-15 21:40:07.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/debian/changelog 2019-12-25 19:55:29.000000000 +0000 @@ -1,3 +1,12 @@ +golang-github-cenkalti-backoff (3.1.1-1) unstable; urgency=medium + + * Team upload + * New upstream release + * Standards-Version: 4.4.1 + * DH to version 12 + + -- Dmitry Smirnov Thu, 26 Dec 2019 06:55:29 +1100 + golang-github-cenkalti-backoff (2.0.0-2) unstable; urgency=medium * Team upload. diff -Nru golang-github-cenkalti-backoff-2.0.0/debian/compat golang-github-cenkalti-backoff-3.1.1/debian/compat --- golang-github-cenkalti-backoff-2.0.0/debian/compat 2019-09-15 21:40:07.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -9 diff -Nru golang-github-cenkalti-backoff-2.0.0/debian/control golang-github-cenkalti-backoff-3.1.1/debian/control --- golang-github-cenkalti-backoff-2.0.0/debian/control 2019-09-15 21:40:07.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/debian/control 2019-12-25 19:52:45.000000000 +0000 @@ -4,11 +4,11 @@ Maintainer: Debian Go Packaging Team Uploaders: Martín Ferrari , Félix Sipma , -Build-Depends: debhelper (>= 9), +Build-Depends: debhelper-compat (= 12), dh-golang (>= 1.17~), golang-any, golang-golang-x-net-dev -Standards-Version: 4.1.4 +Standards-Version: 4.4.1 Vcs-Browser: https://salsa.debian.org/go-team/packages/golang-github-cenkalti-backoff Vcs-Git: https://salsa.debian.org/go-team/packages/golang-github-cenkalti-backoff.git Homepage: https://github.com/cenkalti/backoff diff -Nru golang-github-cenkalti-backoff-2.0.0/example_test.go golang-github-cenkalti-backoff-3.1.1/example_test.go --- golang-github-cenkalti-backoff-2.0.0/example_test.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/example_test.go 2019-11-23 10:56:18.000000000 +0000 @@ -1,9 +1,8 @@ package backoff import ( + "context" "log" - - "golang.org/x/net/context" ) func ExampleRetry() { @@ -21,7 +20,7 @@ // Operation is successful. } -func ExampleRetryContext() { +func ExampleRetryContext() { // nolint: govet // A context ctx := context.Background() @@ -53,7 +52,7 @@ // Ticks will continue to arrive when the previous operation is still running, // so operations that take a while to fail could run in quick succession. - for _ = range ticker.C { + for range ticker.C { if err = operation(); err != nil { log.Println(err, "will retry...") continue @@ -69,5 +68,4 @@ } // Operation is successful. - return } diff -Nru golang-github-cenkalti-backoff-2.0.0/exponential.go golang-github-cenkalti-backoff-3.1.1/exponential.go --- golang-github-cenkalti-backoff-2.0.0/exponential.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/exponential.go 2019-11-23 10:56:18.000000000 +0000 @@ -63,7 +63,6 @@ currentInterval time.Duration startTime time.Time - random *rand.Rand } // Clock is an interface that returns current time for BackOff. @@ -89,7 +88,6 @@ MaxInterval: DefaultMaxInterval, MaxElapsedTime: DefaultMaxElapsedTime, Clock: SystemClock, - random: rand.New(rand.NewSource(time.Now().UnixNano())), } b.Reset() return b @@ -105,23 +103,21 @@ var SystemClock = systemClock{} // Reset the interval back to the initial retry interval and restarts the timer. +// Reset must be called before using b. func (b *ExponentialBackOff) Reset() { b.currentInterval = b.InitialInterval b.startTime = b.Clock.Now() } // NextBackOff calculates the next backoff interval using the formula: -// Randomized interval = RetryInterval +/- (RandomizationFactor * RetryInterval) +// Randomized interval = RetryInterval * (1 ± RandomizationFactor) func (b *ExponentialBackOff) NextBackOff() time.Duration { // Make sure we have not gone over the maximum elapsed time. if b.MaxElapsedTime != 0 && b.GetElapsedTime() > b.MaxElapsedTime { return Stop } defer b.incrementCurrentInterval() - if b.random == nil { - b.random = rand.New(rand.NewSource(time.Now().UnixNano())) - } - return getRandomValueFromInterval(b.RandomizationFactor, b.random.Float64(), b.currentInterval) + return getRandomValueFromInterval(b.RandomizationFactor, rand.Float64(), b.currentInterval) } // GetElapsedTime returns the elapsed time since an ExponentialBackOff instance diff -Nru golang-github-cenkalti-backoff-2.0.0/go.mod golang-github-cenkalti-backoff-3.1.1/go.mod --- golang-github-cenkalti-backoff-2.0.0/go.mod 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/go.mod 2019-11-23 10:56:18.000000000 +0000 @@ -0,0 +1,3 @@ +module github.com/cenkalti/backoff/v3 + +go 1.12 diff -Nru golang-github-cenkalti-backoff-2.0.0/README.md golang-github-cenkalti-backoff-3.1.1/README.md --- golang-github-cenkalti-backoff-2.0.0/README.md 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/README.md 2019-11-23 10:56:18.000000000 +0000 @@ -9,7 +9,10 @@ ## Usage -See https://godoc.org/github.com/cenkalti/backoff#pkg-examples +Import path is `github.com/cenkalti/backoff/v3`. Please note the version part at the end. + +godoc.org does not support modules yet, +so you can use https://godoc.org/gopkg.in/cenkalti/backoff.v3 to view the documentation. ## Contributing @@ -24,7 +27,7 @@ [coveralls]: https://coveralls.io/github/cenkalti/backoff?branch=master [coveralls image]: https://coveralls.io/repos/github/cenkalti/backoff/badge.svg?branch=master -[google-http-java-client]: https://github.com/google/google-http-java-client +[google-http-java-client]: https://github.com/google/google-http-java-client/blob/da1aa993e90285ec18579f1553339b00e19b3ab5/google-http-client/src/main/java/com/google/api/client/util/ExponentialBackOff.java [exponential backoff wiki]: http://en.wikipedia.org/wiki/Exponential_backoff [advanced example]: https://godoc.org/github.com/cenkalti/backoff#example_ diff -Nru golang-github-cenkalti-backoff-2.0.0/retry.go golang-github-cenkalti-backoff-3.1.1/retry.go --- golang-github-cenkalti-backoff-2.0.0/retry.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/retry.go 2019-11-23 10:56:18.000000000 +0000 @@ -15,7 +15,6 @@ // Retry the operation o until it does not return error or BackOff stops. // o is guaranteed to be run at least once. -// It is the caller's responsibility to reset b after Retry returns. // // If o returns a *PermanentError, the operation is not retried, and the // wrapped error is returned. @@ -29,6 +28,7 @@ func RetryNotify(operation Operation, b BackOff, notify Notify) error { var err error var next time.Duration + var t *time.Timer cb := ensureContext(b) @@ -42,7 +42,7 @@ return permanent.Err } - if next = b.NextBackOff(); next == Stop { + if next = cb.NextBackOff(); next == Stop { return err } @@ -50,11 +50,15 @@ notify(err, next) } - t := time.NewTimer(next) + if t == nil { + t = time.NewTimer(next) + defer t.Stop() + } else { + t.Reset(next) + } select { case <-cb.Context().Done(): - t.Stop() return err case <-t.C: } @@ -70,6 +74,10 @@ return e.Err.Error() } +func (e *PermanentError) Unwrap() error { + return e.Err +} + // Permanent wraps the given err in a *PermanentError. func Permanent(err error) *PermanentError { return &PermanentError{ diff -Nru golang-github-cenkalti-backoff-2.0.0/retry_test.go golang-github-cenkalti-backoff-3.1.1/retry_test.go --- golang-github-cenkalti-backoff-2.0.0/retry_test.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/retry_test.go 2019-11-23 10:56:18.000000000 +0000 @@ -1,13 +1,12 @@ package backoff import ( + "context" "errors" "fmt" "log" "testing" "time" - - "golang.org/x/net/context" ) func TestRetry(t *testing.T) { diff -Nru golang-github-cenkalti-backoff-2.0.0/ticker.go golang-github-cenkalti-backoff-3.1.1/ticker.go --- golang-github-cenkalti-backoff-2.0.0/ticker.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/ticker.go 2019-11-23 10:56:18.000000000 +0000 @@ -1,7 +1,6 @@ package backoff import ( - "runtime" "sync" "time" ) @@ -34,7 +33,6 @@ } t.b.Reset() go t.run() - runtime.SetFinalizer(t, (*Ticker).Stop) return t } diff -Nru golang-github-cenkalti-backoff-2.0.0/ticker_test.go golang-github-cenkalti-backoff-3.1.1/ticker_test.go --- golang-github-cenkalti-backoff-2.0.0/ticker_test.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/ticker_test.go 2019-11-23 10:56:18.000000000 +0000 @@ -1,13 +1,12 @@ package backoff import ( + "context" "errors" "fmt" "log" "testing" "time" - - "golang.org/x/net/context" ) func TestTicker(t *testing.T) { @@ -36,7 +35,7 @@ } var err error - for _ = range ticker.C { + for range ticker.C { if err = f(); err != nil { t.Log(err) continue @@ -78,7 +77,7 @@ ticker := NewTicker(b) var err error - for _ = range ticker.C { + for range ticker.C { if err = f(); err != nil { t.Log(err) continue diff -Nru golang-github-cenkalti-backoff-2.0.0/.travis.yml golang-github-cenkalti-backoff-3.1.1/.travis.yml --- golang-github-cenkalti-backoff-2.0.0/.travis.yml 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/.travis.yml 2019-11-23 10:56:18.000000000 +0000 @@ -1,6 +1,6 @@ language: go go: - - 1.3.3 + - 1.7 - 1.x - tip before_install: diff -Nru golang-github-cenkalti-backoff-2.0.0/tries_test.go golang-github-cenkalti-backoff-3.1.1/tries_test.go --- golang-github-cenkalti-backoff-2.0.0/tries_test.go 2018-06-09 07:43:26.000000000 +0000 +++ golang-github-cenkalti-backoff-3.1.1/tries_test.go 2019-11-23 10:56:18.000000000 +0000 @@ -40,7 +40,6 @@ if d == Stop { t.Error("returned Stop after reset") } - } func TestMaxTriesZero(t *testing.T) {