Fix deadlock when responding to contacts sync messages.

pull/1/head
Matthew Chen 8 years ago
parent 93927801ee
commit 9b197fad03

@ -606,21 +606,30 @@ NS_ASSUME_NONNULL_BEGIN
} }
} else if (syncMessage.hasRequest) { } else if (syncMessage.hasRequest) {
if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeContacts) { if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeContacts) {
OWSSyncContactsMessage *syncContactsMessage = // We respond asynchronously because populating the sync message will
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts // create transactions and it's not practical (due to locking in the OWSIdentityManager)
identityManager:self.identityManager // to plumb our transaction through.
profileManager:self.profileManager]; //
DataSource *dataSource = // In rare cases this means we won't respond to the sync request, but that's
[DataSourceValue dataSourceWithSyncMessage:[syncContactsMessage buildPlainTextAttachmentData]]; // acceptable.
[self.messageSender enqueueTemporaryAttachment:dataSource dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
contentType:OWSMimeTypeApplicationOctetStream OWSSyncContactsMessage *syncContactsMessage =
inMessage:syncContactsMessage [[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
success:^{ identityManager:self.identityManager
DDLogInfo(@"%@ Successfully sent Contacts response syncMessage.", self.logTag); profileManager:self.profileManager];
} DataSource *dataSource =
failure:^(NSError *error) { [DataSourceValue dataSourceWithSyncMessage:[syncContactsMessage buildPlainTextAttachmentData]];
DDLogError(@"%@ Failed to send Contacts response syncMessage with error: %@", self.logTag, error); [self.messageSender enqueueTemporaryAttachment:dataSource
}]; contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage
success:^{
DDLogInfo(@"%@ Successfully sent Contacts response syncMessage.", self.logTag);
}
failure:^(NSError *error) {
DDLogError(
@"%@ Failed to send Contacts response syncMessage with error: %@", self.logTag, error);
}];
});
} else if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeGroups) { } else if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeGroups) {
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init]; OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
DataSource *dataSource = [DataSourceValue DataSource *dataSource = [DataSourceValue

Loading…
Cancel
Save