Comments (5)
Hello @JaSei ,
Here is a minimal example as requested.
package main
import (
"errors"
"fmt"
"time"
"github.com/avast/retry-go"
)
func main() {
retry.Do(
func() error {
fmt.Println("Do")
return errors.New("")
},
retry.OnRetry(func(n uint, err error) {
fmt.Println("Attempt: ", n, ": Retrying...")
}),
retry.Delay(time.Nanosecond),
retry.Attempts(3),
)
fmt.Println("Done")
}
Which outputs:
Do
Attempt: 0 : Retrying...
Do
Attempt: 1 : Retrying...
Do
Attempt: 2 : Retrying...
Done
As you can see with the output, we fall in the OnRetry
function even though the max attempt number has been reached and no further attempt of the Do
function will be tried. Logically, the OnRetry
function should only be called if another loop of Do
is ensured.
from retry-go.
Hi @clook OnRetry
happening between a failed try.
Look at the code https://github.com/avast/retry-go/blob/master/retry.go#L123.
from retry-go.
thanks @JaSei
A few lines after, I see this part to avoid waiting after last attempt: https://github.com/avast/retry-go/blob/master/retry.go#L125
So I expect it to happen just after the last attempt (and I can confirm this behavior from our use).
from retry-go.
Sorry @clook, I don't understand well what's wrong?
If you see to this test https://github.com/avast/retry-go/blob/master/retry_test.go#L13 you can see OnRetry
function is called each retry. Can you please send your minimal example?
thanks
from retry-go.
Hi @JaSei,
Thanks for coming back.
I will come with a minimal example asap.
To my mind, what seems wrong to me may be caused by the attempt index starting at 0.
If I take the for
loop starting at https://github.com/avast/retry-go/blob/master/retry.go#L126 with a trivial case:
config.attempts
set to 1retryableFunc
returning systematic error
I expect a single try to fail (and no "retry"), so no call to onRetry
callback function.
But the call will indeed occur at https://github.com/avast/retry-go/blob/master/retry.go#L136 at n = 0
Regarding the test here: https://github.com/avast/retry-go/blob/master/retry_test.go#L34
...it is not covering the number of onRetry
calls, the sum is 0 + 1 + 2 + ... + 8 + 9
, which is 45 for 10 attempts but also 10 calls to onRetry
(the first call has no visible effect on the sum so we can think the sum is from 1 to 9).
A more helpful test to double check the number of onRetry
would be:
retryCount += 1
and
assert.Equal(t, uint(9), retryCount, "right count of retry")
which I think would fail with the current implementation.
Tell me if it makes things clearer.
from retry-go.
Related Issues (20)
- ćšćłćéŽé˘ HOT 1
- Add RetryIfValue option to retry on given values
- Add BreakIf Func on attempt(0), to infinite retry condition break.
- Weird behavior for retry.Attempt(0) HOT 2
- The number of passed in OnRetry is inconsistent
- Default delayType documentation is wrong
- Configuring the retry count to be math.MaxUint leads to memory leaks.
- RetryIf throws away errors HOT 1
- dynamic delay time HOT 1
- Getting the last retry error when cancelled by context HOT 1
- How to get unwrapped error from retry? HOT 2
- Not calling RetryIfFunc when Attempt(0) HOT 3
- Wrapping unrecoverable error makes it impossible to detect HOT 2
- markdown generator tool
- Error.Unwrap unexpectedly returns nil when all attempts are not performed
- Length of Error returned by Do does not reflect number of attempts
- retry.Attempts(0) causes retry to not return error on context timeout
- Implement `Unwrap() []error` for Go 1.20 multi-error support
- How to solve the problem that http.request is closed after reading when using retry-go
- failing test (timeout) on windows 1.20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retry-go.