Replaced reconnect backoff by extra retry

This commit is contained in:
M66B 2020-10-28 18:57:51 +01:00
parent bb1b6b3b63
commit a8690f58cb
1 changed files with 48 additions and 66 deletions

View File

@ -109,11 +109,11 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
static final int DEFAULT_POLL_INTERVAL = 0; // minutes
private static final int OPTIMIZE_KEEP_ALIVE_INTERVAL = 12; // minutes
private static final int OPTIMIZE_POLL_INTERVAL = 15; // minutes
private static final int CONNECT_BACKOFF_START = 8; // seconds
private static final int CONNECT_BACKOFF_MAX = 32; // seconds (totally ~1 minutes)
private static final int CONNECT_BACKOFF_START = 4; // seconds
private static final int CONNECT_BACKOFF_MAX = 32; // seconds (totally 4+8+16+32=1 minute)
private static final int CONNECT_BACKOFF_ALARM_START = 15; // minutes
private static final int CONNECT_BACKOFF_ALARM_MAX = 60; // minutes
private static final long RECONNECT_BACKOFF = 90 * 1000L; // milliseconds
private static final long RECONNECT_BACKOFF = (4 + 8 + 16 + 32 + 64) * 1000L; // milliseconds
private static final int ACCOUNT_ERROR_AFTER = 60; // minutes
private static final int ACCOUNT_ERROR_AFTER_POLL = 4; // times
private static final int BACKOFF_ERROR_AFTER = 16; // seconds
@ -903,16 +903,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
account.deleteNotificationChannel(ServiceSynchronize.this);
}
long ago = new Date().getTime() - lastLost;
if (ago < RECONNECT_BACKOFF)
try {
long backoff = RECONNECT_BACKOFF - ago;
EntityLog.log(ServiceSynchronize.this, account.name + " reconnect backoff=" + (backoff / 1000));
state.acquire(backoff, true);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
}
int errors = 0;
state.setBackoff(CONNECT_BACKOFF_START);
while (state.isRunning() &&
@ -1722,19 +1712,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
if (state.isRunning()) {
long now = new Date().getTime();
int backoff = state.getBackoff();
long cbackoff = (RECONNECT_BACKOFF - (new Date().getTime() - lastLost)) / 1000L;
if (cbackoff > backoff) {
try {
EntityLog.log(this, account.name + " reconnect backoff=" + cbackoff);
state.acquire(cbackoff * 1000L, true);
} catch (InterruptedException ex) {
Log.w(account.name + " cbackoff " + ex.toString());
}
state.setBackoff(CONNECT_BACKOFF_START);
} else {
EntityLog.log(this, account.name + " backoff=" + backoff);
if (backoff <= CONNECT_BACKOFF_MAX) {
int max = CONNECT_BACKOFF_MAX * (lastLost + RECONNECT_BACKOFF < now ? 1 : 2);
EntityLog.log(this, account.name + " backoff=" + backoff + " max=" + max);
if (backoff <= max) {
// Short back-off period, keep device awake
try {
state.acquire(backoff * 1000L, true);
@ -1780,14 +1763,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
}
if (backoff < CONNECT_BACKOFF_MAX)
if (backoff < max)
state.setBackoff(backoff * 2);
else if (backoff == CONNECT_BACKOFF_MAX)
else if (backoff == max)
state.setBackoff(CONNECT_BACKOFF_ALARM_START * 60);
else if (backoff < CONNECT_BACKOFF_ALARM_MAX * 60)
state.setBackoff(backoff * 2);
}
}
currentThread = Thread.currentThread().getId();
}