diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index d9083a651..0c7f3f1c7 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -100,9 +100,6 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa _storageManager = storageManager; _dbConnection = storageManager.newDatabaseConnection; self.dbConnection.objectCacheEnabled = NO; -#if DEBUG - self.dbConnection.permittedTransactions = YDB_AnySyncTransaction; -#endif _messageSender = messageSender; OWSSingletonAssert(); diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m index f40711c6c..d52890ae5 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m @@ -49,6 +49,8 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); YapDatabaseReadWriteTransaction *transaction = protocolContext; + // For consistency, we should only access session state on non-caching connections. + OWSAssert(!transaction.connection.objectCacheEnabled); NSDictionary *_Nullable dictionary = [transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection]; @@ -76,6 +78,8 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSFail(@"%@ subDevicesSessions is deprecated", self.logTag); YapDatabaseReadWriteTransaction *transaction = protocolContext; + // For consistency, we should only access session state on non-caching connections. + OWSAssert(!transaction.connection.objectCacheEnabled); NSDictionary *_Nullable dictionary = [transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection]; @@ -93,6 +97,8 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); YapDatabaseReadWriteTransaction *transaction = protocolContext; + // For consistency, we should only access session state on non-caching connections. + OWSAssert(!transaction.connection.objectCacheEnabled); // We need to ensure subsequent usage of this SessionRecord does not consider this session as "fresh". Normally this // is achieved by marking things as "not fresh" at the point of deserialization - when we fetch a SessionRecord from @@ -136,6 +142,8 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); YapDatabaseReadWriteTransaction *transaction = protocolContext; + // For consistency, we should only access session state on non-caching connections. + OWSAssert(!transaction.connection.objectCacheEnabled); DDLogInfo( @"[TSStorageManager (SessionStore)] deleting session for contact: %@ device: %d", contactIdentifier, deviceId); @@ -159,6 +167,8 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); YapDatabaseReadWriteTransaction *transaction = protocolContext; + // For consistency, we should only access session state on non-caching connections. + OWSAssert(!transaction.connection.objectCacheEnabled); DDLogInfo(@"[TSStorageManager (SessionStore)] deleting all sessions for contact:%@", contactIdentifier); @@ -171,6 +181,8 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); YapDatabaseReadWriteTransaction *transaction = protocolContext; + // For consistency, we should only access session state on non-caching connections. + OWSAssert(!transaction.connection.objectCacheEnabled); DDLogInfo(@"[TSStorageManager (SessionStore)] archiving all sessions for contact: %@", contactIdentifier); diff --git a/SignalServiceKit/src/Util/OWSBackgroundTask.m b/SignalServiceKit/src/Util/OWSBackgroundTask.m index bee9fc046..fbf45dca2 100644 --- a/SignalServiceKit/src/Util/OWSBackgroundTask.m +++ b/SignalServiceKit/src/Util/OWSBackgroundTask.m @@ -80,33 +80,32 @@ DispatchMainThreadSafe(^{ __weak typeof(self) weakSelf = self; self.backgroundTaskId = [CurrentAppContext() beginBackgroundTaskWithExpirationHandler:^{ - // Note the usage of OWSCAssert() to avoid capturing a reference to self. - OWSCAssert([NSThread isMainThread]); + dispatch_async(dispatch_get_main_queue(), ^{ + OWSBackgroundTask *strongSelf = weakSelf; + if (!strongSelf) { + return; + } - OWSBackgroundTask *strongSelf = weakSelf; - if (!strongSelf) { - return; - } + // Make a local copy of completionBlock to ensure that it is called + // exactly once. + BackgroundTaskCompletionBlock _Nullable completionBlock = nil; - // Make a local copy of completionBlock to ensure that it is called - // exactly once. - BackgroundTaskCompletionBlock _Nullable completionBlock = nil; + @synchronized(strongSelf) + { + if (strongSelf.backgroundTaskId == UIBackgroundTaskInvalid) { + return; + } + DDLogInfo(@"%@ %@ background task expired.", strongSelf.logTag, strongSelf.label); + strongSelf.backgroundTaskId = UIBackgroundTaskInvalid; - @synchronized(strongSelf) - { - if (strongSelf.backgroundTaskId == UIBackgroundTaskInvalid) { - return; + completionBlock = strongSelf.completionBlock; + strongSelf.completionBlock = nil; } - DDLogInfo(@"%@ %@ background task expired.", strongSelf.logTag, strongSelf.label); - strongSelf.backgroundTaskId = UIBackgroundTaskInvalid; - - completionBlock = strongSelf.completionBlock; - strongSelf.completionBlock = nil; - } - if (completionBlock) { - completionBlock(BackgroundTaskState_Expired); - } + if (completionBlock) { + completionBlock(BackgroundTaskState_Expired); + } + }); }]; // If a background task could not be begun, call the completion block.