Replaced reconnect backoff by extra retry

pull/187/head
M66B 5 years ago
parent bb1b6b3b63
commit a8690f58cb

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

Loading…
Cancel
Save