Erased messages should not stall attachment jobs

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2022-06-07 15:38:14 -07:00 committed by GitHub
parent ab86217a5c
commit 719cd6467f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 31 deletions

View File

@ -286,12 +286,15 @@ async function _runJob(job?: AttachmentDownloadJobType): Promise<void> {
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<void> {
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();
}
}