From baf419b7b6f40bfa7afe19b433ee4a80104ec58c Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 2 Aug 2018 09:24:38 -0700 Subject: [PATCH] Ensure that we always enqueue in the same order received --- libtextsecure/message_receiver.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 34e2b20a9..438c14017 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -138,6 +138,8 @@ MessageReceiver.prototype.extend({ }, handleRequest(request) { this.incoming = this.incoming || []; + const lastPromise = _.last(this.incoming); + // We do the message decryption here, instead of in the ordered pending queue, // to avoid exposing the time it took us to process messages through the time-to-ack. @@ -165,8 +167,11 @@ MessageReceiver.prototype.extend({ } return this.addToCache(envelope, plaintext).then( - () => { + async () => { request.respond(200, 'OK'); + + // To ensure that we queue in the same order we receive messages + await lastPromise; this.queueEnvelope(envelope); }, error => {