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
This commit is contained in:
Lilia 2017-09-01 16:42:41 +02:00 committed by Scott Nonnenberg
parent 07abe2639f
commit 51cd28bb4a
3 changed files with 14 additions and 26 deletions

View file

@ -202,6 +202,18 @@
color: details.color, color: details.color,
active_at: conversation.get('active_at') || Date.now(), active_at: conversation.get('active_at') || Date.now(),
}).then(resolve, reject); }).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) .then(ev.confirm)

View file

@ -38784,10 +38784,7 @@ MessageReceiver.prototype.extend({
throw new Error('Got empty SyncMessage'); throw new Error('Got empty SyncMessage');
} }
}, },
handleVerified: function(envelope, verified, options) { handleVerified: function(envelope, verified) {
options = options || {};
_.defaults(options, {viaContactSync: false});
var ev = new Event('verified'); var ev = new Event('verified');
ev.confirm = this.removeFromCache.bind(this, envelope); ev.confirm = this.removeFromCache.bind(this, envelope);
ev.verified = { ev.verified = {
@ -38795,7 +38792,6 @@ MessageReceiver.prototype.extend({
destination: verified.destination, destination: verified.destination,
identityKey: verified.identityKey.toArrayBuffer() identityKey: verified.identityKey.toArrayBuffer()
}; };
ev.viaContactSync = options.viaContactSync;
return this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
}, },
handleRead: function(envelope, read) { handleRead: function(envelope, read) {
@ -38825,14 +38821,6 @@ MessageReceiver.prototype.extend({
ev.contactDetails = contactDetails; ev.contactDetails = contactDetails;
results.push(this.dispatchAndWait(ev)); results.push(this.dispatchAndWait(ev));
if (contactDetails.verified) {
results.push(this.handleVerified(
envelope,
contactDetails.verified,
{viaContactSync: true}
));
}
contactDetails = contactBuffer.next(); contactDetails = contactBuffer.next();
} }

View file

@ -533,10 +533,7 @@ MessageReceiver.prototype.extend({
throw new Error('Got empty SyncMessage'); throw new Error('Got empty SyncMessage');
} }
}, },
handleVerified: function(envelope, verified, options) { handleVerified: function(envelope, verified) {
options = options || {};
_.defaults(options, {viaContactSync: false});
var ev = new Event('verified'); var ev = new Event('verified');
ev.confirm = this.removeFromCache.bind(this, envelope); ev.confirm = this.removeFromCache.bind(this, envelope);
ev.verified = { ev.verified = {
@ -544,7 +541,6 @@ MessageReceiver.prototype.extend({
destination: verified.destination, destination: verified.destination,
identityKey: verified.identityKey.toArrayBuffer() identityKey: verified.identityKey.toArrayBuffer()
}; };
ev.viaContactSync = options.viaContactSync;
return this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
}, },
handleRead: function(envelope, read) { handleRead: function(envelope, read) {
@ -574,14 +570,6 @@ MessageReceiver.prototype.extend({
ev.contactDetails = contactDetails; ev.contactDetails = contactDetails;
results.push(this.dispatchAndWait(ev)); results.push(this.dispatchAndWait(ev));
if (contactDetails.verified) {
results.push(this.handleVerified(
envelope,
contactDetails.verified,
{viaContactSync: true}
));
}
contactDetails = contactBuffer.next(); contactDetails = contactBuffer.next();
} }