From 1b9176d44d9f6c3e753cb5ec69fb5987e3d25b84 Mon Sep 17 00:00:00 2001 From: Ivan Nepomnyashchikh Date: Wed, 18 Jun 2025 23:41:14 +0400 Subject: [PATCH 1/2] fix issue #68, update github.com/cenkalti/backoff version --- circuitbreaker.go | 7 +------ circuitbreaker_test.go | 2 +- go.mod | 10 +++++----- go.sum | 4 ++-- panel_test.go | 2 +- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/circuitbreaker.go b/circuitbreaker.go index dd9bc55..d148fdb 100644 --- a/circuitbreaker.go +++ b/circuitbreaker.go @@ -15,11 +15,9 @@ // threshold. It does not matter how long it takes to reach the threshold, but the // failures do need to be consecutive. // -// // When wrapping blocks of code with a Breaker's Call() function, a time out can be // specified. If the time out is reached, the breaker's Fail() function will be called. // -// // Other types of circuit breakers can be easily built by creating a Breaker and // adding a custom TripFunc. A TripFunc is called when a Breaker Fail()s and receives // the breaker as an argument. It then returns true or false to indicate whether the @@ -27,7 +25,6 @@ // // The package also provides a wrapper around an http.Client that wraps all of // the http.Client functions with a Breaker. -// package circuit import ( @@ -37,7 +34,7 @@ import ( "sync/atomic" "time" - "github.com/cenkalti/backoff" + "github.com/cenkalti/backoff/v5" "github.com/facebookgo/clock" ) @@ -139,8 +136,6 @@ func NewBreakerWithOptions(options *Options) *Breaker { if options.BackOff == nil { b := backoff.NewExponentialBackOff() b.InitialInterval = defaultInitialBackOffInterval - b.MaxElapsedTime = defaultBackoffMaxElapsedTime - b.Clock = options.Clock b.Reset() options.BackOff = b } diff --git a/circuitbreaker_test.go b/circuitbreaker_test.go index 79aa143..6d2cec4 100644 --- a/circuitbreaker_test.go +++ b/circuitbreaker_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/cenkalti/backoff" + "github.com/cenkalti/backoff/v5" "github.com/facebookgo/clock" ) diff --git a/go.mod b/go.mod index ee73d9e..705be84 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ -module github.com/rubyist/circuitbreaker +module github.com/rubyist/circuitbreaker/v2 -go 1.21.6 +go 1.23 require ( - github.com/cenkalti/backoff v2.2.1+incompatible // indirect - github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect - github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea // indirect + github.com/cenkalti/backoff/v5 v5.0.2 + github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a + github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea ) diff --git a/go.sum b/go.sum index 28e688b..222cec7 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= -github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8= +github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw= github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA= github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea h1:sKwxy1H95npauwu8vtF95vG/syrL0p8fSZo/XlDg5gk= diff --git a/panel_test.go b/panel_test.go index 28b4aec..a310ca3 100644 --- a/panel_test.go +++ b/panel_test.go @@ -21,7 +21,7 @@ func TestPanelGet(t *testing.T) { t.Errorf("Expected ok to be true") } - a, ok = p.Get("missing") + _, _ = p.Get("missing") } func TestPanelAdd(t *testing.T) { From 877cbb49ff5f0c86eb8007cea2faba3625d0cb31 Mon Sep 17 00:00:00 2001 From: Ivan Nepomnyashchikh Date: Thu, 19 Jun 2025 00:07:24 +0400 Subject: [PATCH 2/2] remove unused defaultBackoffMaxElapsedTime --- circuitbreaker.go | 1 - 1 file changed, 1 deletion(-) diff --git a/circuitbreaker.go b/circuitbreaker.go index d148fdb..fa0786d 100644 --- a/circuitbreaker.go +++ b/circuitbreaker.go @@ -71,7 +71,6 @@ const ( var ( defaultInitialBackOffInterval = 500 * time.Millisecond - defaultBackoffMaxElapsedTime = 0 * time.Second ) // Error codes returned by Call