Skip to content

Colota - Android GPS Location tracker

fix: isolate async failures in batch sync to prevent chunk-level cancellation

Max Dietrich13b2b64e4600
diff --git a/apps/mobile/android/app/src/main/java/com/colota/sync/SyncManager.kt b/apps/mobile/android/app/src/main/java/com/colota/sync/SyncManager.kt
index f4bfbb6b..6cafa3da 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/sync/SyncManager.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/sync/SyncManager.kt
@@ -236,14 +236,19 @@ class SyncManager(
val results = retriable.map { item ->
async {
- val success = networkManager.sendToEndpoint(
- JSONObject(item.payload),
- currentEndpoint,
- currentAuthHeaders,
- currentHttpMethod,
- currentApiFormat
- )
- item.queueId to success
+ try {
+ val success = networkManager.sendToEndpoint(
+ JSONObject(item.payload),
+ currentEndpoint,
+ currentAuthHeaders,
+ currentHttpMethod,
+ currentApiFormat
+ )
+ item.queueId to success
+ } catch (e: Exception) {
+ AppLogger.e(TAG, "Failed to send item ${item.queueId}", e)
+ item.queueId to false
+ }
}
}.awaitAll()
@@ -266,6 +271,14 @@ class SyncManager(
val sentLocationIds = retriable.filter { it.queueId in successfulIds }.map { it.locationId }
dbHelper.markLocationsSent(sentLocationIds)
}
+ if (permanentlyFailedIds.isNotEmpty()) {
+ val failedLocationIds = (retriable + exceeded).filter { it.queueId in permanentlyFailedIds }.map { it.locationId }
+ AppLogger.e(TAG, "Permanently dropping ${failedLocationIds.size} locations after $currentMaxRetries retries: $failedLocationIds")
+ LocationServiceModule.sendSyncErrorEvent(
+ "${failedLocationIds.size} locations dropped after $currentMaxRetries failed retries",
+ getCachedQueuedCount()
+ )
+ }
if (toRemove.isNotEmpty()) {
dbHelper.removeBatchFromQueue(toRemove)