dlmarion opened a new issue, #3414:
URL: https://github.com/apache/accumulo/issues/3414

   **Describe the bug**
   Retry.waitForNextAttempt can pass a negative value to Thread.sleep 
[here](https://github.com/apache/accumulo/blob/2.1/core/src/main/java/org/apache/accumulo/core/util/Retry.java#L183).
 It appears that we might be overflowing `waitFactor` 
[here](https://github.com/apache/accumulo/blob/2.1/core/src/main/java/org/apache/accumulo/core/util/Retry.java#L174)
 which is used when the backOffFactor is greater than `1`. I wonder if 
switching from `Random.nextDouble` to `Random.nextLong` would resolve the issue.
   
   **Versions (OS, Maven, Java, and others, as appropriate):**
    - Affected version(s) of this project: 2.1.0
    - OS: [e.g. CentOS 7.5]
    - Others:
   
   **To Reproduce**
   Add the following to `RetryTest` and run it.
   ```
     @Test
     public void testInfiniteRetryWithBackoff() throws InterruptedException {
       Retry retry = Retry.builder().infiniteRetries().retryAfter(100, 
MILLISECONDS)
           .incrementBy(100, MILLISECONDS).maxWait(2, 
SECONDS).backOffFactor(1.5)
           .logInterval(3, MINUTES).createRetry();
       for (int i = 0; i < Integer.MAX_VALUE; i++) {
         try {
           retry.waitForNextAttempt(log, i + "");
         } catch (IllegalArgumentException e) {
           log.error("Failed on iteration: {}", i);
           throw e;
         }
       }
     }
   ```
   
   The test fails with the error below on iteration 97 for me:
   ```
   java.lang.IllegalArgumentException: timeout value is negative
        at java.base/java.lang.Thread.sleep(Native Method)
        at org.apache.accumulo.core.util.Retry.sleep(Retry.java:194)
        at 
org.apache.accumulo.core.util.Retry.waitForNextAttempt(Retry.java:183)
        at 
org.apache.accumulo.core.util.RetryTest.testInfiniteRetryWithBackoff(RetryTest.java:217)
   ```
   
   **Expected behavior**
   Retry should not pass a negative value to `Thread.sleep`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to