Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Report background task timeouts as failures

laurensprieme87f37e47a1b
diff --git a/mobile/apps/photos/lib/utils/bg_task_utils.dart b/mobile/apps/photos/lib/utils/bg_task_utils.dart
index 5aa6bd2461..f083cd1a0a 100644
--- a/mobile/apps/photos/lib/utils/bg_task_utils.dart
+++ b/mobile/apps/photos/lib/utils/bg_task_utils.dart
@@ -18,6 +18,7 @@ void callbackDispatcher() {
// Deferred error construction: an eagerly created Future.error with no
// listener surfaces as an unhandled exception even on success.
String? failure = "Task didn't run";
+ bool timedOut = false;
final prefs = await SharedPreferences.getInstance();
await runWithLogs(() async {
@@ -36,20 +37,27 @@ void callbackDispatcher() {
).timeout(
BgTaskUtils.taskTimeoutFor(taskName),
onTimeout: () async {
+ timedOut = true;
BgTaskUtils.$.warning(
"TLE, committing seppuku for taskID: $taskName",
);
await BgTaskUtils.releaseResourcesForKill(taskName, prefs);
},
);
- BgTaskUtils.$.info('Task run successful $tlog');
- failure = null;
+ if (timedOut) {
+ failure = "Task timed out";
+ } else {
+ BgTaskUtils.$.info('Task run successful $tlog');
+ failure = null;
+ }
} catch (e) {
BgTaskUtils.$.warning('Task error: $e');
await BgTaskUtils.releaseResourcesForKill(taskName, prefs);
failure = e.toString();
} finally {
- if (Platform.isIOS &&
+ // A timed-out run may still be draining, so its marker stays set.
+ if (!timedOut &&
+ Platform.isIOS &&
taskName == BgTaskUtils.iOSBackgroundProcessingTask) {
await BgTaskUtils.clearProcessingTaskStart(prefs);
}
@@ -128,7 +136,8 @@ class BgTaskUtils {
$.warning(
"Previous background processing task (started "
"${DateTime.fromMicrosecondsSinceEpoch(startTimeMicroseconds)}) did not "
- "finish cleanly; the process was likely killed on OS expiration",
+ "finish cleanly; it timed out while draining or the process was killed "
+ "on OS expiration",
);
}