Add check for internal users around group lock ordering.
This commit is contained in:
parent
9d979217fa
commit
b042945fef
3 changed files with 20 additions and 3 deletions
|
@ -18,4 +18,8 @@ public enum ReentrantSessionLock implements SignalSessionLock {
|
|||
LOCK.lock();
|
||||
return LOCK::unlock;
|
||||
}
|
||||
|
||||
public boolean isHeldByCurrentThread() {
|
||||
return LOCK.isHeldByCurrentThread();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ public final class GroupsV1MigrationUtil {
|
|||
public static void performLocalMigration(@NonNull Context context, @NonNull GroupId.V1 gv1Id) throws IOException
|
||||
{
|
||||
Log.i(TAG, "Beginning local migration! V1 ID: " + gv1Id, new Throwable());
|
||||
try (Closeable ignored = GroupsV2ProcessingLock.acquireGroupProcessingLock()) {
|
||||
try (Closeable ignored = GroupsV2ProcessingLock.acquireGroupProcessingLock(1000)) {
|
||||
if (SignalDatabase.groups().groupExists(gv1Id.deriveV2MigrationGroupId())) {
|
||||
Log.w(TAG, "Group was already migrated! Could have been waiting for the lock.", new Throwable());
|
||||
return;
|
||||
|
|
|
@ -4,6 +4,9 @@ import androidx.annotation.WorkerThread;
|
|||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.crypto.ReentrantSessionLock;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -17,15 +20,25 @@ public final class GroupsV2ProcessingLock {
|
|||
private GroupsV2ProcessingLock() {
|
||||
}
|
||||
|
||||
private static final Lock lock = new ReentrantLock();
|
||||
private static final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@WorkerThread
|
||||
public static Closeable acquireGroupProcessingLock() throws GroupChangeBusyException {
|
||||
if (FeatureFlags.internalUser()) {
|
||||
if (!lock.isHeldByCurrentThread()) {
|
||||
if (SignalDatabase.inTransaction()) {
|
||||
throw new AssertionError("Tried to acquire the group lock inside of a database transaction!");
|
||||
}
|
||||
if (ReentrantSessionLock.INSTANCE.isHeldByCurrentThread()) {
|
||||
throw new AssertionError("Tried to acquire the group lock inside of the ReentrantSessionLock!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return acquireGroupProcessingLock(5000);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
static Closeable acquireGroupProcessingLock(long timeoutMs) throws GroupChangeBusyException {
|
||||
public static Closeable acquireGroupProcessingLock(long timeoutMs) throws GroupChangeBusyException {
|
||||
ThreadUtil.assertNotMainThread();
|
||||
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue