From 6476a4fe73043cf1df0f5099e0b28f6a25e3f8f1 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Mon, 6 Jun 2022 15:13:21 -0700 Subject: [PATCH] Erased messages should not stall attachment jobs --- ts/messageModifiers/AttachmentDownloads.ts | 68 ++++++++++++---------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/ts/messageModifiers/AttachmentDownloads.ts b/ts/messageModifiers/AttachmentDownloads.ts index e1acf7dd32c7..dd7c4edc8c22 100644 --- a/ts/messageModifiers/AttachmentDownloads.ts +++ b/ts/messageModifiers/AttachmentDownloads.ts @@ -286,12 +286,15 @@ async function _runJob(job?: AttachmentDownloadJobType): Promise { Errors.toLogFormat(error) ); - await _addAttachmentToMessage( - message, - _markAttachmentAsTransientError(attachment), - { type, index } - ); - await _finishJob(message, id); + try { + await _addAttachmentToMessage( + message, + _markAttachmentAsTransientError(attachment), + { type, index } + ); + } finally { + await _finishJob(message, id); + } return; } @@ -302,32 +305,35 @@ async function _runJob(job?: AttachmentDownloadJobType): Promise { Errors.toLogFormat(error) ); - // Remove `pending` flag from the attachment. - await _addAttachmentToMessage( - message, - { - ...attachment, - downloadJobId: id, - }, - { type, index } - ); - if (message) { - await saveMessage(message.attributes, { - ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(), - }); + try { + // Remove `pending` flag from the attachment. + await _addAttachmentToMessage( + message, + { + ...attachment, + downloadJobId: id, + }, + { type, index } + ); + if (message) { + await saveMessage(message.attributes, { + ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(), + }); + } + + const failedJob = { + ...job, + pending: 0, + attempts: currentAttempt, + timestamp: + Date.now() + (RETRY_BACKOFF[currentAttempt] || RETRY_BACKOFF[3]), + }; + + await saveAttachmentDownloadJob(failedJob); + } finally { + delete _activeAttachmentDownloadJobs[id]; + _maybeStartJob(); } - - const failedJob = { - ...job, - pending: 0, - attempts: currentAttempt, - timestamp: - Date.now() + (RETRY_BACKOFF[currentAttempt] || RETRY_BACKOFF[3]), - }; - - await saveAttachmentDownloadJob(failedJob); - delete _activeAttachmentDownloadJobs[id]; - _maybeStartJob(); } }