diff --git a/packages/local-sync/src/local-sync-worker/sync-worker.es6 b/packages/local-sync/src/local-sync-worker/sync-worker.es6 index f75731bfc..1657613ea 100644 --- a/packages/local-sync/src/local-sync-worker/sync-worker.es6 +++ b/packages/local-sync/src/local-sync-worker/sync-worker.es6 @@ -406,7 +406,7 @@ class SyncWorker { let reason = "Scheduled" if (error != null) { - reason = `Sync errored` + reason = `Sync errored: ${error.message}` } else if (this._interrupted) { reason = `Sync interrupted and restarted. Interrupt reason: ${reason}` } else if (moreToSync) { @@ -456,10 +456,7 @@ class SyncWorker { const tasks = yield syncbackTaskRunner.getNewSyncbackTasks() this._shouldIgnoreInboxFlagUpdates = true for (const task of tasks) { - const {shouldRetry} = await syncbackTaskRunner.runSyncbackTask(task) - if (shouldRetry) { - this.syncNow({reason: 'Retrying syncback task', interrupt: true}); - } + await syncbackTaskRunner.runSyncbackTask(task) yield // Yield to allow interruption } this._shouldIgnoreInboxFlagUpdates = false diff --git a/packages/local-sync/src/local-sync-worker/syncback-task-runner.es6 b/packages/local-sync/src/local-sync-worker/syncback-task-runner.es6 index 3af1808f8..86a6d478a 100644 --- a/packages/local-sync/src/local-sync-worker/syncback-task-runner.es6 +++ b/packages/local-sync/src/local-sync-worker/syncback-task-runner.es6 @@ -147,7 +147,7 @@ class SyncbackTaskRunner { } const before = new Date(); const syncbackRequest = task.syncbackRequestObject(); - let shouldRetry = false + let retryableError = null this._logger.log(`🔃 📤 ${task.description()}`, syncbackRequest.props) try { @@ -183,7 +183,7 @@ class SyncbackTaskRunner { provider: this._account.provider, errorMessage: error.message, }) - shouldRetry = true + retryableError = error syncbackRequest.status = "NEW"; this._logger.warn(`🔃 📤 ${task.description()} Failed with retryable error, retrying in next loop (${after.getTime() - before.getTime()}ms)`, {syncbackRequest: syncbackRequest.toJSON(), error}) } else { @@ -196,7 +196,13 @@ class SyncbackTaskRunner { } finally { await syncbackRequest.save(); } - return {shouldRetry} + if (retryableError) { + // Throw retryable error to interrupt and restart sync loop + // The sync loop will take care of backing off when handling retryable + // errors. + retryableError.message = `${task.description()} failed with retryable error: ${retryableError.message}` + throw retryableError + } } }