From ffef9d9fe8fdf7ff176b57d975f7610518d47ca8 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Sun, 4 Oct 2009 20:57:03 -0700 Subject: [PATCH] Help with another push inconsistency edge case (#2131432) * If we are forced to abort a "ping" due to a watchdog alarm, we should handle this as a ping failure (which potentially changes the heartbeat) rather than a garden variety IOException. * This prevents the additional overhead of connection error backoffs, which would only tend to increase the time needed to recover from the error. * In one case reported by Moto, this appears to be the behavior of a WiFi router with NAT timeout. This fix will cause maximum delay for pushed mail to be reduced in most cases. Change-Id: I2b0e3b10d82762d20f63cac3ac4638a03f13f842 --- src/com/android/exchange/EasSyncService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java index 540f1a2a0..b2532a1c5 100644 --- a/src/com/android/exchange/EasSyncService.java +++ b/src/com/android/exchange/EasSyncService.java @@ -141,6 +141,8 @@ public class EasSyncService extends AbstractSyncService { private int mPingHighWaterMark = 0; // Whether we've ever lowered the heartbeat private boolean mPingHeartbeatDropped = false; + // Whether a POST was aborted due to watchdog timeout + private boolean mAborted = false; public EasSyncService(Context _context, Mailbox _mailbox) { super(_context, _mailbox); @@ -164,6 +166,7 @@ public class EasSyncService extends AbstractSyncService { synchronized(getSynchronizer()) { if (mPendingPost != null) { userLog("Aborting pending POST!"); + mAborted = true; mPendingPost.abort(); } } @@ -769,7 +772,8 @@ public class EasSyncService extends AbstractSyncService { // haven't yet "fixed" the timeout, back off by two minutes and "fix" it boolean hasMessage = message != null; userLog("IOException runPingLoop: " + (hasMessage ? message : "[no message]")); - if (hasMessage && message.contains("reset by peer")) { + if (mAborted || (hasMessage && message.contains("reset by peer"))) { + long pingLength = SystemClock.elapsedRealtime() - pingTime; if ((pingHeartbeat > PING_MIN_HEARTBEAT) && (pingHeartbeat > mPingHighWaterMark)) { pingHeartbeat -= PING_HEARTBEAT_INCREMENT; @@ -778,8 +782,8 @@ public class EasSyncService extends AbstractSyncService { pingHeartbeat = PING_MIN_HEARTBEAT; } userLog("Decreased ping heartbeat to ", pingHeartbeat, "s"); - } else if ((SystemClock.elapsedRealtime() - pingTime) < 2000) { - userLog("NAT type IOException < 2 seconds; throwing IOException"); + } else if (mAborted || (pingLength < 2000)) { + userLog("Abort or NAT type return < 2 seconds; throwing IOException"); throw e; } else { userLog("NAT type IOException > 2 seconds?");