From 607dd9a2f202f89f4f42a3e4584e81d494c0ed97 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 23 Mar 2017 16:03:46 -0400 Subject: [PATCH] Avoid YapDatabase deadlock in OWSMessageSender. // FREEBIE --- src/Messages/OWSMessageSender.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Messages/OWSMessageSender.m b/src/Messages/OWSMessageSender.m index fab12e5eb..eb33b3e1c 100644 --- a/src/Messages/OWSMessageSender.m +++ b/src/Messages/OWSMessageSender.m @@ -862,9 +862,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return; } + // Getting the local number uses a transaction, so we need to do that before we + // create a new transaction to avoid deadlock. + NSString *contactId = [TSAccountManager localNumber]; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { TSContactThread *cThread = - [TSContactThread getOrCreateThreadWithContactId:[TSAccountManager localNumber] transaction:transaction]; + [TSContactThread getOrCreateThreadWithContactId:contactId transaction:transaction]; [cThread saveWithTransaction:transaction]; TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:(outgoingMessage.timestamp + 1)