Coder Social home page Coder Social logo

OnRetry terminology is ambiguous about retry-go HOT 5 OPEN

clook avatar clook commented on August 20, 2024 1
OnRetry terminology is ambiguous

from retry-go.

Comments (5)

RaJiska avatar RaJiska commented on August 20, 2024 1

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.

JaSei avatar JaSei commented on August 20, 2024

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.

clook avatar clook commented on August 20, 2024

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.

JaSei avatar JaSei commented on August 20, 2024

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.

clook avatar clook commented on August 20, 2024

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 1
  • retryableFunc 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.