Fix pending retry receipt cache deadlock.

This commit is contained in:
Clark
2023-06-15 09:50:22 -04:00
committed by Cody Henthorne
parent ec6b1a44de
commit 0437d37f23

View File

@@ -23,10 +23,15 @@ class PendingRetryReceiptCache @VisibleForTesting constructor(
fun insert(author: RecipientId, authorDevice: Int, sentTimestamp: Long, receivedTimestamp: Long, threadId: Long) {
if (!FeatureFlags.retryReceipts()) return
ensurePopulated()
val model: PendingRetryReceiptModel = database.insert(author, authorDevice, sentTimestamp, receivedTimestamp, threadId)
synchronized(pendingRetries) {
val model: PendingRetryReceiptModel = database.insert(author, authorDevice, sentTimestamp, receivedTimestamp, threadId)
pendingRetries[RemoteMessageId(author, sentTimestamp)] = model
val key = RemoteMessageId(author, sentTimestamp)
val existing: PendingRetryReceiptModel? = pendingRetries[key]
// We rely on db unique constraint and auto-incrementing ids for conflict resolution here.
if (existing == null || existing.id < model.id) {
pendingRetries[key] = model
}
}
}
@@ -54,8 +59,8 @@ class PendingRetryReceiptCache @VisibleForTesting constructor(
synchronized(pendingRetries) {
pendingRetries.remove(RemoteMessageId(model.author, model.sentTimestamp))
database.delete(model)
}
database.delete(model)
}
fun clear() {