Avoid deadlock

There are multiple methods which synchronize(self) in TSAccountMessage and also
multiple ones which can occur within a read-write transaction.
pull/2/head
Michael Kirk 7 years ago
parent b374955f80
commit b55e0e45f5

@ -259,8 +259,11 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
- (uint32_t)getOrGenerateRegistrationId:(YapDatabaseReadWriteTransaction *)transaction
{
@synchronized(self)
{
// Unlike other methods in this class, there's no need for a `@synchronized` block
// here, since we're already in a write transaction, and all writes occur on a serial queue.
//
// Since other code in this class which uses @synchronized(self) also needs to open write
// transaction, using @synchronized(self) here, inside of a WriteTransaction risks deadlock.
uint32_t registrationID = [[transaction objectForKey:TSAccountManager_LocalRegistrationIdKey
inCollection:TSAccountManager_UserAccountCollection] unsignedIntValue];
@ -273,7 +276,6 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
inCollection:TSAccountManager_UserAccountCollection];
}
return registrationID;
}
}
- (void)registerForPushNotificationsWithPushToken:(NSString *)pushToken

Loading…
Cancel
Save