diff options
| author | 2016-05-25 17:18:08 -0700 | |
|---|---|---|
| committer | 2016-05-25 18:13:30 -0700 | |
| commit | c1c8325619aeae3ba23d69e2385071c26e3f57af (patch) | |
| tree | bad039b691c6c7f81f444dff9933576167cff6f8 | |
| parent | a1984286d397e4198d4e26572fb54cd55dce6d20 (diff) | |
Use backstop timeouts on asynchronous countdown during preflight
Work around nebulous lost-timeout issues by adding a backstop timeout
to "wait for result" latch operations. When we hit these, the initial
conditions will be reported as final result; so make those intial states
match the error condition that is appropriate to such a timeout.
Bug 28963707
Change-Id: I4d21a86c48e87633118b1e6eaa05c1d966efec81
| -rw-r--r-- | services/backup/java/com/android/server/backup/BackupManagerService.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index 1ab816085660..acc2ec30d67f 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -146,6 +146,7 @@ import java.util.Random; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -4664,7 +4665,7 @@ public class BackupManagerService { // a standalone thread. The runner owns this half of the pipe, and closes // it to indicate EOD to the other end. class SinglePackageBackupPreflight implements BackupRestoreTask, FullBackupPreflight { - final AtomicLong mResult = new AtomicLong(); + final AtomicLong mResult = new AtomicLong(BackupTransport.AGENT_ERROR); final CountDownLatch mLatch = new CountDownLatch(1); final IBackupTransport mTransport; @@ -4684,8 +4685,13 @@ public class BackupManagerService { } agent.doMeasureFullBackup(token, mBackupManagerBinder); - // now wait to get our result back - mLatch.await(); + // Now wait to get our result back. If this backstop timeout is reached without + // the latch being thrown, flow will continue as though a result or "normal" + // timeout had been produced. In case of a real backstop timeout, mResult + // will still contain the value it was constructed with, AGENT_ERROR, which + // intentionaly falls into the "just report failure" code. + mLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS); + long totalSize = mResult.get(); // If preflight timed out, mResult will contain error code as int. if (totalSize < 0) { @@ -4738,7 +4744,7 @@ public class BackupManagerService { @Override public long getExpectedSizeOrErrorCode() { try { - mLatch.await(); + mLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS); return mResult.get(); } catch (InterruptedException e) { return BackupTransport.NO_MORE_DATA; @@ -4763,8 +4769,8 @@ public class BackupManagerService { mPreflight = new SinglePackageBackupPreflight(transport); mPreflightLatch = new CountDownLatch(1); mBackupLatch = new CountDownLatch(1); - mPreflightResult = BackupTransport.TRANSPORT_OK; - mBackupResult = BackupTransport.TRANSPORT_OK; + mPreflightResult = BackupTransport.AGENT_ERROR; + mBackupResult = BackupTransport.AGENT_ERROR; } @Override @@ -4801,7 +4807,7 @@ public class BackupManagerService { // otherwise return negative error code. long getPreflightResultBlocking() { try { - mPreflightLatch.await(); + mPreflightLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS); if (mPreflightResult == BackupTransport.TRANSPORT_OK) { return mPreflight.getExpectedSizeOrErrorCode(); } else { @@ -4814,7 +4820,7 @@ public class BackupManagerService { int getBackupResultBlocking() { try { - mBackupLatch.await(); + mBackupLatch.await(TIMEOUT_FULL_BACKUP_INTERVAL, TimeUnit.MILLISECONDS); return mBackupResult; } catch (InterruptedException e) { return BackupTransport.AGENT_ERROR; |