Skip to content

Commit ea51e70

Browse files
MichalSzewczykvelo
authored andcommitted
Fixes retrials without Thread.sleep when thread gets interrupted (OpenFeign#627)
* Fixes retrials without Thread.sleep when thread gets interrupted * Added test to verify if default retryer propagates RetryableException exception when thread is interrupted
1 parent c2fcbed commit ea51e70

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

core/src/main/java/feign/Retryer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void continueOrPropagate(RetryableException e) {
7373
Thread.sleep(interval);
7474
} catch (InterruptedException ignored) {
7575
Thread.currentThread().interrupt();
76+
throw e;
7677
}
7778
sleptForMillis += interval;
7879
}

core/src/test/java/feign/RetryerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package feign;
1515

16+
import org.junit.Assert;
1617
import org.junit.Rule;
1718
import org.junit.Test;
1819
import org.junit.rules.ExpectedException;
@@ -72,4 +73,21 @@ protected long currentTimeMillis() {
7273
public void neverRetryAlwaysPropagates() {
7374
Retryer.NEVER_RETRY.continueOrPropagate(new RetryableException(null, null, new Date(5000)));
7475
}
76+
77+
@Test
78+
public void defaultRetryerFailsOnInterruptedException() {
79+
Default retryer = new Retryer.Default();
80+
81+
Thread.currentThread().interrupt();
82+
RetryableException expected = new RetryableException(null, null, new Date(System.currentTimeMillis() + 5000));
83+
try {
84+
retryer.continueOrPropagate(expected);
85+
Thread.interrupted(); // reset interrupted flag in case it wasn't
86+
Assert.fail("Retryer continued despite interruption");
87+
} catch (RetryableException e) {
88+
Assert.assertTrue("Interrupted status not reset", Thread.interrupted());
89+
Assert.assertEquals("Retry attempt not registered as expected", 2, retryer.attempt);
90+
Assert.assertEquals("Unexpected exception found", expected, e);
91+
}
92+
}
7593
}

0 commit comments

Comments
 (0)