Skip to content

Commit 6fef9fb

Browse files
authored
Don't treat scheduled uploads we discover on CDN as errors
1 parent 9a305d3 commit 6fef9fb

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

SignalServiceKit/Backups/Attachments/BackupAttachmentDownloadQueueRunner.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ public class BackupAttachmentDownloadQueueRunnerImpl: BackupAttachmentDownloadQu
420420
progress: progressSink
421421
)
422422
} catch let error {
423+
if Task.isCancelled {
424+
logger.info("Cancelled; stopping the queue")
425+
try? await loader.stop(reason: CancellationError())
426+
return .retryableError(CancellationError())
427+
}
428+
423429
switch await statusManager.jobDidExperienceError(error, token: statusToken, mode: mode) {
424430
case nil:
425431
// No state change, keep going.

SignalServiceKit/Backups/Attachments/BackupAttachmentUploadQueueRunner.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ class BackupAttachmentUploadQueueRunnerImpl: BackupAttachmentUploadQueueRunner {
508508
)
509509
}
510510
} catch let error {
511+
if Task.isCancelled {
512+
logger.info("Cancelled; stopping the queue")
513+
try? await loader.stop(reason: CancellationError())
514+
return .retryableError(CancellationError())
515+
}
516+
511517
switch error as? BackupArchive.Response.CopyToMediaTierError {
512518
case .sourceObjectNotFound:
513519
// Any time we find this error, retry. It means the upload

SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,24 @@ private class ListMediaIntegrityCheckerImpl: ListMediaIntegrityChecker {
14081408
return
14091409
} else {
14101410
// We've discovered this upload on the media tier.
1411-
_result[keyPath: resultKeyPath(isFullsize: isFullsize)].discoveredOnCdnCount += 1
1412-
_result[keyPath: resultKeyPath(isFullsize: isFullsize)].addSampleId(attachment.id, \.discoveredOnCdnSampleAttachmentIds)
1411+
let enqueuedUpload = try? backupAttachmentUploadStore.getEnqueuedUpload(
1412+
for: attachment.id,
1413+
fullsize: isFullsize,
1414+
tx: tx
1415+
)
1416+
switch enqueuedUpload?.state {
1417+
case .ready:
1418+
// If it was enqueued for upload, its possible we previously attempted to upload
1419+
// and succeeded server-side but got interrupted before updating local state after,
1420+
// so its still in the upload queue. This is ok; we would have re-attempted upload
1421+
// and found it already uploaded, given the chance.
1422+
return
1423+
case .done, nil:
1424+
// If it was not in the queue, that means discovering it on the server is unexpected.
1425+
_result[keyPath: resultKeyPath(isFullsize: isFullsize)].discoveredOnCdnCount += 1
1426+
_result[keyPath: resultKeyPath(isFullsize: isFullsize)].addSampleId(attachment.id, \.discoveredOnCdnSampleAttachmentIds)
1427+
return
1428+
}
14131429
}
14141430
case remoteCdnNumber:
14151431
// Local and remote state match

0 commit comments

Comments
 (0)