From eb589c05246ffeb49bb3bd634883db31be00d4f4 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 23 Sep 2020 20:31:37 +0200 Subject: [PATCH] Prevent interrupting backoff --- app/src/main/java/eu/faircode/email/Core.java | 10 +++++----- .../java/eu/faircode/email/ServiceSynchronize.java | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 0de4667716..7119f1f611 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -4056,7 +4056,7 @@ class Core { static class State { private int backoff; - private boolean keepalive = false; + private boolean backingoff = false; private ConnectionHelper.NetworkState networkState; private Thread thread = new Thread(); private Semaphore semaphore = new Semaphore(0); @@ -4101,12 +4101,12 @@ class Core { return true; } - boolean acquire(long milliseconds, boolean keepalive) throws InterruptedException { + boolean acquire(long milliseconds, boolean backingoff) throws InterruptedException { try { - this.keepalive = keepalive; + this.backingoff = backingoff; return semaphore.tryAcquire(milliseconds, TimeUnit.MILLISECONDS); } finally { - this.keepalive = false; + this.backingoff = false; } } @@ -4137,7 +4137,7 @@ class Core { if (ex instanceof OperationCanceledException) recoverable = false; - if (keepalive) { + if (!backingoff) { thread.interrupt(); yield(); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 292b409578..95ef965965 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -899,7 +899,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { long backoff = RECONNECT_BACKOFF - ago; EntityLog.log(ServiceSynchronize.this, account.name + " reconnect backoff=" + (backoff / 1000)); - state.acquire(backoff, false); + state.acquire(backoff, true); } catch (InterruptedException ex) { Log.w(account.name + " backoff " + ex.toString()); } @@ -1535,7 +1535,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { wlAccount.release(); - state.acquire(2 * duration, true); + state.acquire(2 * duration, false); Log.i("### " + account.name + " keeping alive"); } catch (InterruptedException ex) { EntityLog.log(this, account.name + " waited state=" + state); @@ -1653,7 +1653,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (cbackoff > backoff) { try { EntityLog.log(this, account.name + " reconnect backoff=" + cbackoff); - state.acquire(cbackoff * 1000L, false); + state.acquire(cbackoff * 1000L, true); } catch (InterruptedException ex) { Log.w(account.name + " cbackoff " + ex.toString()); } @@ -1663,7 +1663,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (backoff <= CONNECT_BACKOFF_MAX) { // Short back-off period, keep device awake try { - state.acquire(backoff * 1000L, false); + state.acquire(backoff * 1000L, true); } catch (InterruptedException ex) { Log.w(account.name + " backoff " + ex.toString()); } @@ -1696,7 +1696,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences try { wlAccount.release(); - state.acquire(2 * backoff * 1000L, false); + state.acquire(2 * backoff * 1000L, true); Log.i("### " + account.name + " backoff done"); } catch (InterruptedException ex) { Log.w(account.name + " backoff " + ex.toString());