1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Fix 'endless' loop in ImapFolderPusher

Under certain circumstances it's possible that the 'push state' isn't
updated to contain the most recent 'UIDNEXT' value. In that case
ImapFolderPusher.start() would execute the same code path through its
main loop over and over again, preventing the device from going to
sleep.
Rather than changing the code to update the 'push state' in the corner
case that triggers the behavior described above, this commit introduces
another mechanism to track the 'UIDNEXT' value. This should also catch
as of yet unknown cases where the 'push state' isn't properly updated.

At some point in the future I hope we get to a point where we only
persist the 'push state' when we manually stop/restart the service.
During normal operation there's no need to read from/write to storage
all the time.

Fixes issue 4907
This commit is contained in:
cketti 2014-02-11 20:17:34 +01:00
parent d419fab789
commit 3527930f89

View File

@ -2978,6 +2978,7 @@ public class ImapStore extends Store {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Pusher starting for " + getLogId());
long lastUidNext = -1L;
while (!stop.get()) {
try {
long oldUidNext = -1L;
@ -2990,6 +2991,18 @@ public class ImapStore extends Store {
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get oldUidNext for " + getLogId(), e);
}
/*
* This makes sure 'oldUidNext' is never smaller than 'UIDNEXT' from
* the last loop iteration. This way we avoid looping endlessly causing
* the battery to drain.
*
* See issue 4907
*/
if (oldUidNext < lastUidNext) {
oldUidNext = lastUidNext;
}
ImapConnection oldConnection = mConnection;
internalOpen(OPEN_MODE_RO);
ImapConnection conn = mConnection;
@ -3041,6 +3054,8 @@ public class ImapStore extends Store {
if (startUid < 1) {
startUid = 1;
}
lastUidNext = newUidNext;
if (newUidNext > startUid) {
if (K9.DEBUG)