Skip to content

Commit 3830733

Browse files
committed
Fix back-off retries
1 parent a0eb18f commit 3830733

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/ExponentialBackOffTimesPolicy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ final class ExponentialBackOffTimesPolicy implements BackOffTimesPolicy {
5151
FIVE_SECONDS_IN_MILLIS,
5252
FOUR_MINUTES_IN_MILLIS,
5353
FIVE_SECONDS_IN_MILLIS,
54-
SIX_MINUTES_IN_MILLIS,
55-
FIVE_SECONDS_IN_MILLIS
54+
SIX_MINUTES_IN_MILLIS
5655
};
5756

5857
@Override

core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/SenderThreadLocalBackOffData.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,8 @@ public void onDoneSending() {
8787
public long backOffTimerValue() {
8888
try {
8989
lock.lock();
90-
++currentBackOffIndex;
91-
if (currentBackOffIndex == backOffTimeoutsInMillis.length) {
92-
currentBackOffIndex = -1;
93-
94-
// Exhausted the back-offs
95-
return -1;
96-
}
90+
// when the last backoff index is hit, stay there until backoff is reset
91+
currentBackOffIndex = Math.min(currentBackOffIndex + 1, backOffTimeoutsInMillis.length - 1);
9792

9893
if (!instanceIsActive) {
9994
return 0;

core/src/test/java/com/microsoft/applicationinsights/internal/channel/common/ExponentialBackOffTimesPolicyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class ExponentialBackOffTimesPolicyTest {
3535
public void testBackOffs() {
3636
long[] backOffs = new ExponentialBackOffTimesPolicy().getBackOffTimeoutsInMillis();
3737
assertNotNull(backOffs);
38-
assertTrue(backOffs.length % 2 == 1);
38+
assertTrue(backOffs.length % 2 == 0);
3939
int couples = backOffs.length / 2;
4040
long lastEventValue = BackOffTimesPolicy.MIN_TIME_TO_BACK_OFF_IN_MILLS;
4141
for (int i = 0; i < couples; ++i) {

0 commit comments

Comments
 (0)