Fix deadlock

This commit is contained in:
Niels Andriesse 2019-10-31 13:49:25 +11:00
parent 3e5546ab78
commit 14fbce0880
2 changed files with 7 additions and 4 deletions

View File

@ -82,10 +82,13 @@ NS_ASSUME_NONNULL_BEGIN
return (preKeyRecord != nil);
}
- (void)removePreKey:(int)preKeyId
- (void)removePreKey:(int)preKeyId protocolContext:(nullable id)protocolContext
{
[self.dbReadWriteConnection removeObjectForKey:[self keyFromInt:preKeyId]
inCollection:OWSPrimaryStoragePreKeyStoreCollection];
if ([protocolContext isKindOfClass:YapDatabaseReadWriteTransaction.class]) {
[(YapDatabaseReadWriteTransaction *)protocolContext removeObjectForKey:[self keyFromInt:preKeyId] inCollection:OWSPrimaryStoragePreKeyStoreCollection];
} else {
[self.dbReadWriteConnection removeObjectForKey:[self keyFromInt:preKeyId] inCollection:OWSPrimaryStoragePreKeyStoreCollection];
}
}
- (int)nextPreKeyId:(int)batchSize

View File

@ -54,7 +54,7 @@
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
PreKeyRecord *firstPreKeyRecord = [generatedKeys firstObject];
[[OWSPrimaryStorage sharedManager] removePreKey:lastPreKeyRecord.Id];
[[OWSPrimaryStorage sharedManager] removePreKey:lastPreKeyRecord.Id protocolContext:nil];
XCTAssertThrows([[OWSPrimaryStorage sharedManager] throws_loadPreKey:lastPreKeyRecord.Id]);
XCTAssertNoThrow([[OWSPrimaryStorage sharedManager] throws_loadPreKey:firstPreKeyRecord.Id]);