Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry.Attempts(0) causes retry to not return error on context timeout #83

Closed
merusso opened this issue Jan 16, 2023 · 0 comments · Fixed by #84
Closed

retry.Attempts(0) causes retry to not return error on context timeout #83

merusso opened this issue Jan 16, 2023 · 0 comments · Fixed by #84

Comments

@merusso
Copy link

merusso commented Jan 16, 2023

Problem

When using retry.Option retry.Attempts(0), this changes retry's error handling behavior for a timed-out context. retry.Do returns a nil response instead of an error.

Tested versions with this issue:

  • v4.3.1
  • v4.3.2

Expected

When a context times out, retry.Do should terminate and return an error.

Actual

When using retry.Attempts(0) and a context times out, retry.Do returns with no error, implying success. When retry.Attempts is not set or is set to another value, retry.Do returns an error.

Workaround

Set retry.Attempts to a large number, e.g. retry.Attempts(99999999)

Test

func TestRetry_timeoutWithAttempts0(t *testing.T) {
	g := NewGomegaWithT(t)

	// Test 1, default retry.Attempts (=10)
	// Passes

	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()

	err := retry.Do(func() error {
		return errors.New("simulated error")
	}, retry.Context(ctx))
	g.Expect(err).To(HaveOccurred())

	ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()

	// Test 2, retry.Attempts(0)
	// Fails

	err = retry.Do(func() error {
		return errors.New("simulated error")
	}, retry.Context(ctx), retry.Attempts(0))
	g.Expect(err).To(HaveOccurred())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant