diff --git a/ts/messageModifiers/AttachmentDownloads.ts b/ts/messageModifiers/AttachmentDownloads.ts index eb890fa00..d6fa1bc18 100644 --- a/ts/messageModifiers/AttachmentDownloads.ts +++ b/ts/messageModifiers/AttachmentDownloads.ts @@ -333,30 +333,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); } } diff --git a/ts/services/profiles.ts b/ts/services/profiles.ts index 99c58057b..514eed213 100644 --- a/ts/services/profiles.ts +++ b/ts/services/profiles.ts @@ -485,6 +485,9 @@ async function doGetProfile(c: ConversationModel): Promise { ); c.set({ profileKeyCredential, profileKeyCredentialExpiration }); } else { + log.warn( + 'getProfile: Included credential request, but got no credential. Clearing profileKeyCredential.' + ); c.unset('profileKeyCredential'); } } diff --git a/ts/test-electron/WebsocketResources_test.ts b/ts/test-electron/WebsocketResources_test.ts index ea71804e3..dfe544460 100644 --- a/ts/test-electron/WebsocketResources_test.ts +++ b/ts/test-electron/WebsocketResources_test.ts @@ -230,8 +230,8 @@ describe('WebSocket-Resource', () => { assert.strictEqual(message.request?.path, '/'); assert.strictEqual( Date.now(), - startTime + 60000, - 'keepalive time should be one minute' + startTime + 30000 + 5000, + 'keepalive time should be 35s' ); done(); }); diff --git a/ts/textsecure/WebsocketResources.ts b/ts/textsecure/WebsocketResources.ts index 2878c8e69..e13c55146 100644 --- a/ts/textsecure/WebsocketResources.ts +++ b/ts/textsecure/WebsocketResources.ts @@ -386,8 +386,8 @@ export type KeepAliveOptionsType = { disconnect?: boolean; }; -const KEEPALIVE_INTERVAL_MS = 55000; // 55 seconds + 5 seconds for closing the -// socket above. +// 30 seconds + 5 seconds for closing the socket above. +const KEEPALIVE_INTERVAL_MS = 30 * durations.SECOND; const MAX_KEEPALIVE_INTERVAL_MS = 5 * durations.MINUTE; class KeepAlive {