From 604563a3b40b8d2d800686191b097fcdec1d1c26 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:31:03 -0500 Subject: [PATCH] Prevent decryptAndCache jobs from delaying message sends --- ts/textsecure/MessageReceiver.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 9c97f08875a1..ee733d174abe 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -343,9 +343,7 @@ export default class MessageReceiver wait: 75, maxSize: 30, processBatch: (items: Array) => { - // Not returning the promise here because we don't want to stall - // the batch. - void this.decryptAndCacheBatch(items); + return this.decryptAndCacheBatch(items); }, }); this.cacheRemoveBatcher = createBatcher({ @@ -1150,6 +1148,16 @@ export default class MessageReceiver return; } + // Now, queue and process decrypted envelopes. We drop the promise so that the next + // decryptAndCacheBatch batch does not have to wait for the decrypted envelopes to be + // processed, which can be an asynchronous blocking operation + drop(this.queueAllDecryptedEnvelopes(decrypted)); + } + + // The final step in decryptAndCacheBatch: queue the decrypted envelopes for processing + private async queueAllDecryptedEnvelopes( + decrypted: Array> + ): Promise { await Promise.all( decrypted.map(async ({ envelope, plaintext }) => { try {