Fix child transaction causing batch to be discarded.
This commit is contained in:
parent
82db08b76f
commit
159c0d1104
2 changed files with 17 additions and 25 deletions
|
@ -398,23 +398,21 @@ class IncomingMessageObserver(private val context: Application) {
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
GroupsV2ProcessingLock.acquireGroupProcessingLock().use {
|
GroupsV2ProcessingLock.acquireGroupProcessingLock().use {
|
||||||
ReentrantSessionLock.INSTANCE.acquire().use {
|
ReentrantSessionLock.INSTANCE.acquire().use {
|
||||||
|
batch.forEach {
|
||||||
SignalDatabase.runInTransaction {
|
SignalDatabase.runInTransaction {
|
||||||
val followUpOperations: List<FollowUpOperation> = batch
|
val followUpOperations: List<FollowUpOperation>? = processEnvelope(bufferedStore, it.envelope, it.serverDeliveredTimestamp)
|
||||||
.mapNotNull { processEnvelope(bufferedStore, it.envelope, it.serverDeliveredTimestamp) }
|
|
||||||
.flatten()
|
|
||||||
|
|
||||||
bufferedStore.flushToDisk()
|
bufferedStore.flushToDisk()
|
||||||
|
if (followUpOperations != null) {
|
||||||
val jobs = followUpOperations.mapNotNull { it.run() }
|
val jobs = followUpOperations.mapNotNull { it.run() }
|
||||||
ApplicationDependencies.getJobManager().addAll(jobs)
|
ApplicationDependencies.getJobManager().addAll(jobs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
signalWebSocket.sendAck(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val duration = System.currentTimeMillis() - startTime
|
val duration = System.currentTimeMillis() - startTime
|
||||||
Log.d(TAG, "Decrypted ${batch.size} envelopes in $duration ms (~${duration / batch.size} ms per message)")
|
Log.d(TAG, "Decrypted ${batch.size} envelopes in $duration ms (~${duration / batch.size} ms per message)")
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attempts = 0
|
attempts = 0
|
||||||
|
|
|
@ -273,22 +273,16 @@ public final class SignalWebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responses.size() > 0) {
|
if (responses.size() > 0) {
|
||||||
boolean successfullyProcessed = false;
|
callback.onMessageBatch(responses);
|
||||||
|
|
||||||
try {
|
|
||||||
successfullyProcessed = callback.onMessageBatch(responses);
|
|
||||||
} finally {
|
|
||||||
if (successfullyProcessed) {
|
|
||||||
for (EnvelopeResponse response : responses) {
|
|
||||||
getWebSocket().sendResponse(createWebSocketResponse(response.getWebsocketRequest()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !hitEndOfQueue;
|
return !hitEndOfQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendAck(EnvelopeResponse response) throws IOException {
|
||||||
|
getWebSocket().sendResponse(createWebSocketResponse(response.getWebsocketRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("DuplicateThrows")
|
@SuppressWarnings("DuplicateThrows")
|
||||||
private Optional<EnvelopeResponse> waitForSingleMessage(long timeout)
|
private Optional<EnvelopeResponse> waitForSingleMessage(long timeout)
|
||||||
throws TimeoutException, WebSocketUnavailableException, IOException
|
throws TimeoutException, WebSocketUnavailableException, IOException
|
||||||
|
@ -370,7 +364,7 @@ public final class SignalWebSocket {
|
||||||
*/
|
*/
|
||||||
public interface MessageReceivedCallback {
|
public interface MessageReceivedCallback {
|
||||||
|
|
||||||
/** True if you successfully processed the message, otherwise false. **/
|
/** Called with the batch of envelopes. You are responsible for sending acks. **/
|
||||||
boolean onMessageBatch(List<EnvelopeResponse> envelopeResponses);
|
void onMessageBatch(List<EnvelopeResponse> envelopeResponses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue