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 is making an extra attempt #31

Open
redkhalil opened this issue May 10, 2019 · 2 comments
Open

Retry is making an extra attempt #31

redkhalil opened this issue May 10, 2019 · 2 comments

Comments

@redkhalil
Copy link

redkhalil commented May 10, 2019

I'm not sure why but I'm getting an extra call to my promise
Looks like the retry is occurring correctly since logged "Retrying request" matches my retry attempt.
The last attempt is the one that looks extraneous. Would you be able to advise why?

Therefore if I use Directly(1) I'm seeting my request sent 3 times instead of 2.

def sendWithRetry[U](promise: => Future[U], retryPolicy: retry.Policy): Future[U] = {
    val retryOnSpecifiedFailurePolicy = retry.When {
      case CustomException() =>
        logger.warn("Retrying request...")
        retryPolicy
    }

    retryOnSpecifiedFailurePolicy(promise)
  }

I'm calling the above like this
sendWithRetry(send(message), retry.Directly(1))
and I have this defined in class scope
implicit val always: retry.Success[Any] = retry.Success.always

@redkhalil
Copy link
Author

redkhalil commented May 11, 2019

This test for retry.When is failing

it ("retry is making an extra attempt") {
      implicit val success = Success[Boolean](identity)

      class MyException extends RuntimeException
      val thrownEx = new MyException

      val called = new AtomicInteger()

      def run(): Future[Boolean] = {
        info(s"Attempt ${called.incrementAndGet()}")
        Future.failed(thrownEx)
      }

      val policy = retry.When {
        // lift an exception into a new policy
        case _:MyException => Directly(1)
      }

      whenReady(policy(run).failed) { _ =>
        assert(called.get() === 2)
      }
    }

If you replace Directly(1) with Pause(1, 1.second) you'll notice that the first 2 attempts are made back-to-back while the third one is made after the 1 second delay.
I was expecting 2 attempts only with the second one delayed by 1 second.

@redkhalil redkhalil changed the title Getting extra call and don't know why Retry is making an extra attempt May 11, 2019
@herzrasen
Copy link

Did you find any solution to this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants