Skip to content

armgit / ente

Public Imported from GitHub
0

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

remove timeout and error handling, keep only logging

Prateek Sunalc073cd7f0860
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index d315365164..26950479fc 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -181,44 +181,12 @@ Future<void> _runMinimally(String taskId, TimeLogger tlog) async {
_logger.info("[BG TASK] update notification");
}
updateService.showUpdateNotification().ignore();
-
- // Wrap _sync() with timeout and error handling to prevent indefinite hanging
- // and allow background tasks to complete even if sync fails
- try {
- if (flagService.internalUser) {
- _logger.info("[BG TASK] sync starting with 5-minute timeout");
- }
- await _sync('bgTaskActiveProcess').timeout(
- const Duration(minutes: 5),
- onTimeout: () {
- if (flagService.internalUser) {
- _logger.severe(
- "[BG TASK] Sync timed out after 5 minutes! "
- "Continuing with home widget and smart albums sync.",
- );
- }
- throw TimeoutException(
- 'Background sync exceeded 5-minute timeout',
- const Duration(minutes: 5),
- );
- },
- );
- if (flagService.internalUser) {
- _logger.info("[BG TASK] sync completed successfully");
- }
- } on TimeoutException catch (e) {
- if (flagService.internalUser) {
- _logger.severe("[BG TASK] Sync timeout caught, continuing...", e);
- }
- } catch (e, s) {
- if (flagService.internalUser) {
- _logger.severe(
- "[BG TASK] Sync failed with error. "
- "Continuing with home widget and smart albums sync.",
- e,
- s,
- );
- }
+ if (flagService.internalUser) {
+ _logger.info("[BG TASK] sync starting");
+ }
+ await _sync('bgTaskActiveProcess');
+ if (flagService.internalUser) {
+ _logger.info("[BG TASK] sync completed");
}
if (flagService.internalUser) {
diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
index 73744f9454..2902ee29ad 100644
--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
@@ -600,8 +600,6 @@ class RemoteSyncService {
_completedUploads = 0;
_ignoredUploads = 0;
final int toBeUploaded = filesToBeUploaded.length + updatedFileIDs.length;
- // Track if pre-upload checks pass - used to decide whether to queue uploads
- bool preUploadChecksPassed = false;
if (toBeUploaded > 0) {
if (flagService.internalUser) {
@@ -640,325 +638,290 @@ class RemoteSyncService {
_logger.info("[UPLOAD-DEBUG] Fired preparingForUpload status update");
}
- // Wrap all pre-upload checks in try-catch to handle failures gracefully
- // This allows sync to complete and background tasks to continue to home widget/smart albums
- try {
- // Step 1: Verify media location access permission
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Step 1/3: Checking media location access permission...",
- );
- }
- await _uploader.verifyMediaLocationAccess();
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Step 1/3: Media location access verified βœ“",
- );
- }
+ // Step 1: Verify media location access permission
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Step 1/3: Checking media location access permission...",
+ );
+ }
+ await _uploader.verifyMediaLocationAccess();
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Step 1/3: Media location access verified βœ“",
+ );
+ }
- // Step 2: Check network availability for upload
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Step 2/3: Checking network availability for upload...",
- );
- }
- await _uploader.checkNetworkForUpload();
- if (flagService.internalUser) {
- _logger.info("[UPLOAD-DEBUG] Step 2/3: Network check passed βœ“");
- }
+ // Step 2: Check network availability for upload
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Step 2/3: Checking network availability for upload...",
+ );
+ }
+ await _uploader.checkNetworkForUpload();
+ if (flagService.internalUser) {
+ _logger.info("[UPLOAD-DEBUG] Step 2/3: Network check passed βœ“");
+ }
+
+ // Step 3: Fetch upload URLs from server
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Step 3/3: Fetching upload URLs from server for $toBeUploaded files...",
+ );
+ }
+ await _uploader.fetchUploadURLs(toBeUploaded);
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Step 3/3: Upload URLs fetched successfully βœ“",
+ );
+ }
+
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] All pre-upload checks completed successfully! "
+ "Proceeding to queue individual file uploads...",
+ );
+ }
+ } else {
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] No files to upload, skipping upload preparation",
+ );
+ }
+ }
+ final List<Future> futures = [];
- // Step 3: Fetch upload URLs from server
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Starting to queue ${filesToBeUploaded.length} new files for upload...",
+ );
+ }
+ int queuedCount = 0;
+ for (final file in filesToBeUploaded) {
+ if (shouldThrottleUpload &&
+ futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Step 3/3: Fetching upload URLs from server for $toBeUploaded files...",
+ "[UPLOAD-DEBUG] Throttle limit reached (${futures.length} files queued). "
+ "Skipping remaining ${filesToBeUploaded.length - queuedCount} files.",
);
}
- await _uploader.fetchUploadURLs(toBeUploaded);
+ break;
+ }
+ // prefer existing collection ID for manually uploaded files.
+ // See https://github.com/ente-io/photos-app/pull/187
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Queueing file ${queuedCount + 1}/${filesToBeUploaded.length}: "
+ "${file.title} (localID: ${file.localID}, generatedID: ${file.generatedID})",
+ );
+ }
+ try {
+ final collectionID = file.collectionID ??
+ (await _collectionsService.getOrCreateForPath(
+ file.deviceFolder ?? 'Unknown Folder',
+ ))
+ .id;
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Step 3/3: Upload URLs fetched successfully βœ“",
+ "[UPLOAD-DEBUG] Resolved collectionID: $collectionID for file ${file.title}",
);
}
-
- preUploadChecksPassed = true;
+ _uploadFile(file, collectionID, futures);
+ queuedCount++;
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] All pre-upload checks completed successfully! "
- "Proceeding to queue individual file uploads...",
+ "[UPLOAD-DEBUG] Successfully queued file ${file.title} ($queuedCount queued so far)",
);
}
} catch (e, s) {
if (flagService.internalUser) {
_logger.severe(
- "[UPLOAD-DEBUG] Pre-upload checks FAILED. "
- "Skipping upload phase but allowing sync to complete gracefully. "
- "This ensures home widget and smart albums can still sync.",
+ "[UPLOAD-DEBUG] Failed to queue file ${file.title}",
e,
s,
);
}
- // Don't rethrow - allow sync to complete without uploads
}
+ }
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Finished queueing new files. Total queued: $queuedCount/${filesToBeUploaded.length}",
+ );
+ }
- if (!preUploadChecksPassed) {
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Starting to queue ${updatedFileIDs.length} updated files for re-upload...",
+ );
+ }
+ int reuploadQueuedCount = 0;
+ for (final uploadedFileID in updatedFileIDs) {
+ if (shouldThrottleUpload &&
+ futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Skipping file upload queue due to failed pre-upload checks. "
- "Sync will complete without uploading $toBeUploaded files.",
+ "[UPLOAD-DEBUG] Throttle limit reached for re-uploads (${futures.length} total queued). "
+ "Skipping remaining ${updatedFileIDs.length - reuploadQueuedCount} updated files.",
);
}
+ break;
}
- } else {
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] No files to upload, skipping upload preparation",
+ "[UPLOAD-DEBUG] Processing updated file ${reuploadQueuedCount + 1}/${updatedFileIDs.length} "
+ "(uploadedFileID: $uploadedFileID)",
);
}
- }
- final List<Future> futures = [];
-
- // Only proceed with queueing uploads if pre-upload checks passed
- if (preUploadChecksPassed) {
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Starting to queue ${filesToBeUploaded.length} new files for upload...",
+ try {
+ final allFiles = await _db.getFilesInAllCollection(
+ uploadedFileID,
+ ownerID,
);
- }
- int queuedCount = 0;
- for (final file in filesToBeUploaded) {
- if (shouldThrottleUpload &&
- futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
+ if (allFiles.isEmpty) {
if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Throttle limit reached (${futures.length} files queued). "
- "Skipping remaining ${filesToBeUploaded.length - queuedCount} files.",
+ _logger.warning(
+ "[UPLOAD-DEBUG] No files found for uploadedFileID $uploadedFileID, skipping",
);
}
- break;
+ continue;
}
- // prefer existing collection ID for manually uploaded files.
- // See https://github.com/ente-io/photos-app/pull/187
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Queueing file ${queuedCount + 1}/${filesToBeUploaded.length}: "
- "${file.title} (localID: ${file.localID}, generatedID: ${file.generatedID})",
+ "[UPLOAD-DEBUG] Found ${allFiles.length} file(s) for uploadedFileID $uploadedFileID",
);
}
- try {
- final collectionID = file.collectionID ??
- (await _collectionsService.getOrCreateForPath(
- file.deviceFolder ?? 'Unknown Folder',
- ))
- .id;
+ EnteFile? fileInCollectionOwnedByUser;
+ for (final file in allFiles) {
+ if (file.canReUpload(ownerID)) {
+ fileInCollectionOwnedByUser = file;
+ break;
+ }
+ }
+ if (fileInCollectionOwnedByUser != null) {
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Resolved collectionID: $collectionID for file ${file.title}",
+ "[UPLOAD-DEBUG] Queueing re-upload for ${fileInCollectionOwnedByUser.title}",
);
}
- _uploadFile(file, collectionID, futures);
- queuedCount++;
+ _uploadFile(
+ fileInCollectionOwnedByUser,
+ fileInCollectionOwnedByUser.collectionID!,
+ futures,
+ );
+ reuploadQueuedCount++;
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Successfully queued file ${file.title} ($queuedCount queued so far)",
+ "[UPLOAD-DEBUG] Successfully queued re-upload ($reuploadQueuedCount re-uploads queued)",
);
}
- } catch (e, s) {
+ } else {
if (flagService.internalUser) {
- _logger.severe(
- "[UPLOAD-DEBUG] Failed to queue file ${file.title}",
- e,
- s,
+ _logger.warning(
+ "[UPLOAD-DEBUG] No re-uploadable file found for uploadedFileID $uploadedFileID",
);
}
}
+ } catch (e, s) {
+ if (flagService.internalUser) {
+ _logger.severe(
+ "[UPLOAD-DEBUG] Failed to queue re-upload for uploadedFileID $uploadedFileID",
+ e,
+ s,
+ );
+ }
}
+ }
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] Finished queueing updated files. Total re-uploads queued: "
+ "$reuploadQueuedCount/${updatedFileIDs.length}",
+ );
+ }
+
+ if (flagService.internalUser) {
+ _logger.info(
+ "[UPLOAD-DEBUG] ═══════════════════════════════════════════════════════",
+ );
+ _logger.info(
+ "[UPLOAD-DEBUG] SUMMARY: Total ${futures.length} upload futures queued",
+ );
+ _logger.info(
+ "[UPLOAD-DEBUG] - New files queued: $queuedCount/${filesToBeUploaded.length}",
+ );
+ _logger.info(
+ "[UPLOAD-DEBUG] - Re-uploads queued: $reuploadQueuedCount/${updatedFileIDs.length}",
+ );
+ _logger.info(
+ "[UPLOAD-DEBUG] - Process mode: ${isProcessBg ? 'BACKGROUND' : 'FOREGROUND'}",
+ );
+ _logger.info(
+ "[UPLOAD-DEBUG] Now waiting for all ${futures.length} upload futures to complete...",
+ );
+ _logger.info(
+ "[UPLOAD-DEBUG] ═══════════════════════════════════════════════════════",
+ );
+ }
+
+ try {
+ await Future.wait(futures);
if (flagService.internalUser) {
_logger.info(
- "[UPLOAD-DEBUG] Finished queueing new files. Total queued: $queuedCount/${filesToBeUploaded.length}",
+ "[UPLOAD-DEBUG] All upload futures completed successfully! "
+ "Completed: $_completedUploads, Ignored: $_ignoredUploads",
);
}
-
+ } on InvalidFileError catch (e, s) {
if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Starting to queue ${updatedFileIDs.length} updated files for re-upload...",
+ _logger.warning(
+ "[UPLOAD-DEBUG] InvalidFileError caught (ignored)",
+ e,
+ s,
);
}
- int reuploadQueuedCount = 0;
- for (final uploadedFileID in updatedFileIDs) {
- if (shouldThrottleUpload &&
- futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Throttle limit reached for re-uploads (${futures.length} total queued). "
- "Skipping remaining ${updatedFileIDs.length - reuploadQueuedCount} updated files.",
- );
- }
- break;
- }
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Processing updated file ${reuploadQueuedCount + 1}/${updatedFileIDs.length} "
- "(uploadedFileID: $uploadedFileID)",
- );
- }
- try {
- final allFiles = await _db.getFilesInAllCollection(
- uploadedFileID,
- ownerID,
- );
- if (allFiles.isEmpty) {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] No files found for uploadedFileID $uploadedFileID, skipping",
- );
- }
- continue;
- }
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Found ${allFiles.length} file(s) for uploadedFileID $uploadedFileID",
- );
- }
- EnteFile? fileInCollectionOwnedByUser;
- for (final file in allFiles) {
- if (file.canReUpload(ownerID)) {
- fileInCollectionOwnedByUser = file;
- break;
- }
- }
- if (fileInCollectionOwnedByUser != null) {
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Queueing re-upload for ${fileInCollectionOwnedByUser.title}",
- );
- }
- _uploadFile(
- fileInCollectionOwnedByUser,
- fileInCollectionOwnedByUser.collectionID!,
- futures,
- );
- reuploadQueuedCount++;
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Successfully queued re-upload ($reuploadQueuedCount re-uploads queued)",
- );
- }
- } else {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] No re-uploadable file found for uploadedFileID $uploadedFileID",
- );
- }
- }
- } catch (e, s) {
- if (flagService.internalUser) {
- _logger.severe(
- "[UPLOAD-DEBUG] Failed to queue re-upload for uploadedFileID $uploadedFileID",
- e,
- s,
- );
- }
- }
- }
+ // Do nothing
+ } on FileSystemException catch (e, s) {
if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Finished queueing updated files. Total re-uploads queued: "
- "$reuploadQueuedCount/${updatedFileIDs.length}",
+ _logger.warning(
+ "[UPLOAD-DEBUG] FileSystemException caught (ignored - likely concurrency issue)",
+ e,
+ s,
);
}
-
+ // Do nothing since it's caused mostly due to concurrency issues
+ // when the foreground app deletes temporary files, interrupting a background
+ // upload
+ } on LockAlreadyAcquiredError catch (e, s) {
if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] ═══════════════════════════════════════════════════════",
- );
- _logger.info(
- "[UPLOAD-DEBUG] SUMMARY: Total ${futures.length} upload futures queued",
- );
- _logger.info(
- "[UPLOAD-DEBUG] - New files queued: $queuedCount/${filesToBeUploaded.length}",
- );
- _logger.info(
- "[UPLOAD-DEBUG] - Re-uploads queued: $reuploadQueuedCount/${updatedFileIDs.length}",
- );
- _logger.info(
- "[UPLOAD-DEBUG] - Process mode: ${isProcessBg ? 'BACKGROUND' : 'FOREGROUND'}",
- );
- _logger.info(
- "[UPLOAD-DEBUG] Now waiting for all ${futures.length} upload futures to complete...",
- );
- _logger.info(
- "[UPLOAD-DEBUG] ═══════════════════════════════════════════════════════",
+ _logger.warning(
+ "[UPLOAD-DEBUG] LockAlreadyAcquiredError caught (ignored)",
+ e,
+ s,
);
}
-
- try {
- await Future.wait(futures);
- if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] All upload futures completed successfully! "
- "Completed: $_completedUploads, Ignored: $_ignoredUploads",
- );
- }
- } on InvalidFileError catch (e, s) {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] InvalidFileError caught (ignored)",
- e,
- s,
- );
- }
- // Do nothing
- } on FileSystemException catch (e, s) {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] FileSystemException caught (ignored - likely concurrency issue)",
- e,
- s,
- );
- }
- // Do nothing since it's caused mostly due to concurrency issues
- // when the foreground app deletes temporary files, interrupting a background
- // upload
- } on LockAlreadyAcquiredError catch (e, s) {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] LockAlreadyAcquiredError caught (ignored)",
- e,
- s,
- );
- }
- // Do nothing
- } on SilentlyCancelUploadsError catch (e, s) {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] SilentlyCancelUploadsError caught (ignored)",
- e,
- s,
- );
- }
- // Do nothing
- } on UserCancelledUploadError catch (e, s) {
- if (flagService.internalUser) {
- _logger.warning(
- "[UPLOAD-DEBUG] UserCancelledUploadError caught (ignored)",
- e,
- s,
- );
- }
- // Do nothing
- } catch (e, s) {
- if (flagService.internalUser) {
- _logger.severe("[UPLOAD-DEBUG] Unexpected error during upload", e, s);
- }
- rethrow;
+ // Do nothing
+ } on SilentlyCancelUploadsError catch (e, s) {
+ if (flagService.internalUser) {
+ _logger.warning(
+ "[UPLOAD-DEBUG] SilentlyCancelUploadsError caught (ignored)",
+ e,
+ s,
+ );
}
- } else {
+ // Do nothing
+ } on UserCancelledUploadError catch (e, s) {
if (flagService.internalUser) {
- _logger.info(
- "[UPLOAD-DEBUG] Skipped upload queueing because pre-upload checks failed. "
- "Sync completing without uploads to allow background task to continue.",
+ _logger.warning(
+ "[UPLOAD-DEBUG] UserCancelledUploadError caught (ignored)",
+ e,
+ s,
);
}
+ // Do nothing
+ } catch (e, s) {
+ if (flagService.internalUser) {
+ _logger.severe("[UPLOAD-DEBUG] Unexpected error during upload", e, s);
+ }
+ rethrow;
}
final hasUploaded = _completedUploads > 0;