Make attachments more resilient, decrease websocket keepalive
This commit is contained in:
parent
ce77465d23
commit
932043c58f
4 changed files with 35 additions and 27 deletions
|
@ -333,30 +333,35 @@ async function _runJob(job?: AttachmentDownloadJobType): Promise<void> {
|
||||||
Errors.toLogFormat(error)
|
Errors.toLogFormat(error)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove `pending` flag from the attachment.
|
try {
|
||||||
await _addAttachmentToMessage(
|
// Remove `pending` flag from the attachment.
|
||||||
message,
|
await _addAttachmentToMessage(
|
||||||
{
|
message,
|
||||||
...attachment,
|
{
|
||||||
downloadJobId: id,
|
...attachment,
|
||||||
},
|
downloadJobId: id,
|
||||||
{ type, index }
|
},
|
||||||
);
|
{ type, index }
|
||||||
if (message) {
|
);
|
||||||
await saveMessage(message.attributes, {
|
if (message) {
|
||||||
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -485,6 +485,9 @@ async function doGetProfile(c: ConversationModel): Promise<void> {
|
||||||
);
|
);
|
||||||
c.set({ profileKeyCredential, profileKeyCredentialExpiration });
|
c.set({ profileKeyCredential, profileKeyCredentialExpiration });
|
||||||
} else {
|
} else {
|
||||||
|
log.warn(
|
||||||
|
'getProfile: Included credential request, but got no credential. Clearing profileKeyCredential.'
|
||||||
|
);
|
||||||
c.unset('profileKeyCredential');
|
c.unset('profileKeyCredential');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,8 +230,8 @@ describe('WebSocket-Resource', () => {
|
||||||
assert.strictEqual(message.request?.path, '/');
|
assert.strictEqual(message.request?.path, '/');
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
Date.now(),
|
Date.now(),
|
||||||
startTime + 60000,
|
startTime + 30000 + 5000,
|
||||||
'keepalive time should be one minute'
|
'keepalive time should be 35s'
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
|
@ -386,8 +386,8 @@ export type KeepAliveOptionsType = {
|
||||||
disconnect?: boolean;
|
disconnect?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const KEEPALIVE_INTERVAL_MS = 55000; // 55 seconds + 5 seconds for closing the
|
// 30 seconds + 5 seconds for closing the socket above.
|
||||||
// socket above.
|
const KEEPALIVE_INTERVAL_MS = 30 * durations.SECOND;
|
||||||
const MAX_KEEPALIVE_INTERVAL_MS = 5 * durations.MINUTE;
|
const MAX_KEEPALIVE_INTERVAL_MS = 5 * durations.MINUTE;
|
||||||
|
|
||||||
class KeepAlive {
|
class KeepAlive {
|
||||||
|
|
Loading…
Reference in a new issue