fix backoff overflow #107

This commit is contained in:
Naoyuki Kanezawa
2015-03-07 22:10:09 +09:00
parent 13492ddd07
commit d6e22703b8
2 changed files with 17 additions and 0 deletions

View File

@@ -17,6 +17,10 @@ public class Backoff {
int deviation = (int) Math.floor(rand * this.jitter * ms);
ms = (((int) Math.floor(rand * 10)) & 1) == 0 ? ms - deviation : ms + deviation;
}
if (ms < this.ms) {
// overflow happened
ms = Long.MAX_VALUE;
}
return Math.min(ms, this.max);
}