From 8f7fe5c3eeb693e132b3c7d8bc692546bd70d27d Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Sat, 16 Jan 2021 03:37:11 -0500 Subject: [PATCH] Add jitter to job exponential backoff. --- .../thoughtcrime/securesms/jobmanager/JobController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java index 90c63bd17e..07306970c3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java @@ -453,9 +453,12 @@ class JobController { } private long calculateNextRunAttemptTime(long currentTime, int nextAttempt, long maxBackoff) { - int boundedAttempt = Math.min(nextAttempt, 30); - long exponentialBackoff = (long) Math.pow(2, boundedAttempt) * 1000; - long actualBackoff = Math.min(exponentialBackoff, maxBackoff); + int boundedAttempt = Math.min(nextAttempt, 30); + long exponentialBackoff = (long) Math.pow(2, boundedAttempt) * 1000; + long actualBackoff = Math.min(exponentialBackoff, maxBackoff); + double jitter = 0.75 + (Math.random() * 0.5); + + actualBackoff = (long) (actualBackoff * jitter); return currentTime + actualBackoff; }