From 51cd28bb4a4209ad00fc051a249083561009d6d6 Mon Sep 17 00:00:00 2001 From: Lilia Date: Fri, 1 Sep 2017 16:42:41 +0200 Subject: [PATCH] Fix race handling contact sync with verified info (#1419) When processing a contact sync with embedded identity key verification info, we were running overlapping async fetch/save operations on the same conversation model, causing a race that tends to clobber updates to the contact info. In this change we extend the application-level contact info handler to block on a subsequent call to the verification handler, which effectively serializes the fetch/save calls, and relieves the need for the message receiver to trigger a seperate event concerning the verification info on contact sync messages. Fixes #1408 // FREEBIE --- js/background.js | 12 ++++++++++++ js/libtextsecure.js | 14 +------------- libtextsecure/message_receiver.js | 14 +------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/js/background.js b/js/background.js index 8bc517440e6..31620cea597 100644 --- a/js/background.js +++ b/js/background.js @@ -202,6 +202,18 @@ color: details.color, active_at: conversation.get('active_at') || Date.now(), }).then(resolve, reject); + }).then(function() { + if (details.verified) { + var verified = details.verified; + var ev = new Event('verified'); + ev.verified = { + state: verified.state, + destination: verified.destination, + identityKey: verified.identityKey.toArrayBuffer(), + }; + ev.viaContactSync = true; + return onVerified(ev); + } }); }) .then(ev.confirm) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 8651517b9ce..0ad65de17fc 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38784,10 +38784,7 @@ MessageReceiver.prototype.extend({ throw new Error('Got empty SyncMessage'); } }, - handleVerified: function(envelope, verified, options) { - options = options || {}; - _.defaults(options, {viaContactSync: false}); - + handleVerified: function(envelope, verified) { var ev = new Event('verified'); ev.confirm = this.removeFromCache.bind(this, envelope); ev.verified = { @@ -38795,7 +38792,6 @@ MessageReceiver.prototype.extend({ destination: verified.destination, identityKey: verified.identityKey.toArrayBuffer() }; - ev.viaContactSync = options.viaContactSync; return this.dispatchAndWait(ev); }, handleRead: function(envelope, read) { @@ -38825,14 +38821,6 @@ MessageReceiver.prototype.extend({ ev.contactDetails = contactDetails; results.push(this.dispatchAndWait(ev)); - if (contactDetails.verified) { - results.push(this.handleVerified( - envelope, - contactDetails.verified, - {viaContactSync: true} - )); - } - contactDetails = contactBuffer.next(); } diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 302451424e6..8b4269b44a4 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -533,10 +533,7 @@ MessageReceiver.prototype.extend({ throw new Error('Got empty SyncMessage'); } }, - handleVerified: function(envelope, verified, options) { - options = options || {}; - _.defaults(options, {viaContactSync: false}); - + handleVerified: function(envelope, verified) { var ev = new Event('verified'); ev.confirm = this.removeFromCache.bind(this, envelope); ev.verified = { @@ -544,7 +541,6 @@ MessageReceiver.prototype.extend({ destination: verified.destination, identityKey: verified.identityKey.toArrayBuffer() }; - ev.viaContactSync = options.viaContactSync; return this.dispatchAndWait(ev); }, handleRead: function(envelope, read) { @@ -574,14 +570,6 @@ MessageReceiver.prototype.extend({ ev.contactDetails = contactDetails; results.push(this.dispatchAndWait(ev)); - if (contactDetails.verified) { - results.push(this.handleVerified( - envelope, - contactDetails.verified, - {viaContactSync: true} - )); - } - contactDetails = contactBuffer.next(); }