Prevent possibility of recursively enqueuing early message jobs.

This commit is contained in:
Greyson Parrelli 2022-04-04 19:01:32 -04:00 committed by Cody Henthorne
parent 44efda8318
commit b109effc94
5 changed files with 32 additions and 14 deletions

View file

@ -48,7 +48,7 @@ class PushProcessEarlyMessagesJob private constructor(parameters: Parameters) :
if (contents.isPresent) { if (contents.isPresent) {
for (content: SignalServiceContent in contents.get()) { for (content: SignalServiceContent in contents.get()) {
Log.i(TAG, "[${id.sentTimestamp}] Processing early content for $id") Log.i(TAG, "[${id.sentTimestamp}] Processing early content for $id")
MessageContentProcessor(context).process(MessageContentProcessor.MessageState.DECRYPTED_OK, content, null, id.sentTimestamp, -1) MessageContentProcessor.forEarlyContent(context).process(MessageContentProcessor.MessageState.DECRYPTED_OK, content, null, id.sentTimestamp, -1)
} }
} else { } else {
Log.w(TAG, "[${id.sentTimestamp}] Saw $id in the cache, but when we went to retrieve it, it was already gone.") Log.w(TAG, "[${id.sentTimestamp}] Saw $id in the cache, but when we went to retrieve it, it was already gone.")

View file

@ -189,7 +189,7 @@ public final class PushProcessMessageJob extends BaseJob {
@Override @Override
public void onRun() throws Exception { public void onRun() throws Exception {
MessageContentProcessor processor = new MessageContentProcessor(context); MessageContentProcessor processor = MessageContentProcessor.forNormalContent(context);
processor.process(messageState, content, exceptionMetadata, timestamp, smsMessageId); processor.process(messageState, content, exceptionMetadata, timestamp, smsMessageId);
} }

View file

@ -142,7 +142,7 @@ public class IncomingMessageProcessor {
stopwatch.split("group-check"); stopwatch.split("group-check");
try { try {
MessageContentProcessor processor = new MessageContentProcessor(context); MessageContentProcessor processor = MessageContentProcessor.forNormalContent(context);
processor.process(result.getState(), result.getContent(), result.getException(), envelope.getTimestamp(), -1); processor.process(result.getState(), result.getContent(), result.getException(), envelope.getTimestamp(), -1);
return null; return null;
} catch (IOException | GroupChangeBusyException e) { } catch (IOException | GroupChangeBusyException e) {

View file

@ -195,9 +195,19 @@ public final class MessageContentProcessor {
private static final String TAG = Log.tag(MessageContentProcessor.class); private static final String TAG = Log.tag(MessageContentProcessor.class);
private final Context context; private final Context context;
private final boolean processingEarlyContent;
public MessageContentProcessor(@NonNull Context context) { public static MessageContentProcessor forNormalContent(@NonNull Context context) {
this.context = context; return new MessageContentProcessor(context, false);
}
public static MessageContentProcessor forEarlyContent(@NonNull Context context) {
return new MessageContentProcessor(context, true);
}
private MessageContentProcessor(@NonNull Context context, boolean processingEarlyContent) {
this.context = context;
this.processingEarlyContent = processingEarlyContent;
} }
/** /**
@ -895,8 +905,10 @@ public final class MessageContentProcessor {
if (targetMessage == null) { if (targetMessage == null) {
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Could not find matching message! Putting it in the early message cache. timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId()); warn(String.valueOf(content.getTimestamp()), "[handleReaction] Could not find matching message! Putting it in the early message cache. timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
ApplicationDependencies.getEarlyMessageCache().store(targetAuthor.getId(), reaction.getTargetSentTimestamp(), content); if (!processingEarlyContent) {
PushProcessEarlyMessagesJob.enqueue(); ApplicationDependencies.getEarlyMessageCache().store(targetAuthor.getId(), reaction.getTargetSentTimestamp(), content);
PushProcessEarlyMessagesJob.enqueue();
}
return null; return null;
} }
@ -952,8 +964,10 @@ public final class MessageContentProcessor {
return new MessageId(targetMessage.getId(), targetMessage.isMms()); return new MessageId(targetMessage.getId(), targetMessage.isMms());
} else if (targetMessage == null) { } else if (targetMessage == null) {
warn(String.valueOf(content.getTimestamp()), "[handleRemoteDelete] Could not find matching message! timestamp: " + delete.getTargetSentTimestamp() + " author: " + senderRecipient.getId()); warn(String.valueOf(content.getTimestamp()), "[handleRemoteDelete] Could not find matching message! timestamp: " + delete.getTargetSentTimestamp() + " author: " + senderRecipient.getId());
ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), delete.getTargetSentTimestamp(), content); if (!processingEarlyContent) {
PushProcessEarlyMessagesJob.enqueue(); ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), delete.getTargetSentTimestamp(), content);
PushProcessEarlyMessagesJob.enqueue();
}
return null; return null;
} else { } else {
warn(String.valueOf(content.getTimestamp()), String.format(Locale.ENGLISH, "[handleRemoteDelete] Invalid remote delete! deleteTime: %d, targetTime: %d, deleteAuthor: %s, targetAuthor: %s", warn(String.valueOf(content.getTimestamp()), String.format(Locale.ENGLISH, "[handleRemoteDelete] Invalid remote delete! deleteTime: %d, targetTime: %d, deleteAuthor: %s, targetAuthor: %s",
@ -2131,10 +2145,12 @@ public final class MessageContentProcessor {
for (SyncMessageId id : unhandled) { for (SyncMessageId id : unhandled) {
warn(String.valueOf(content.getTimestamp()), "[handleViewedReceipt] Could not find matching message! timestamp: " + id.getTimetamp() + " author: " + senderRecipient.getId()); warn(String.valueOf(content.getTimestamp()), "[handleViewedReceipt] Could not find matching message! timestamp: " + id.getTimetamp() + " author: " + senderRecipient.getId());
ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), id.getTimetamp(), content); if (!processingEarlyContent) {
ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), id.getTimetamp(), content);
}
} }
if (unhandled.size() > 0) { if (unhandled.size() > 0 && !processingEarlyContent) {
PushProcessEarlyMessagesJob.enqueue(); PushProcessEarlyMessagesJob.enqueue();
} }
} }
@ -2184,10 +2200,12 @@ public final class MessageContentProcessor {
for (SyncMessageId id : unhandled) { for (SyncMessageId id : unhandled) {
warn(String.valueOf(content.getTimestamp()), "[handleReadReceipt] Could not find matching message! timestamp: " + id.getTimetamp() + " author: " + senderRecipient.getId()); warn(String.valueOf(content.getTimestamp()), "[handleReadReceipt] Could not find matching message! timestamp: " + id.getTimetamp() + " author: " + senderRecipient.getId());
ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), id.getTimetamp(), content); if (!processingEarlyContent) {
ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), id.getTimetamp(), content);
}
} }
if (unhandled.size() > 0) { if (unhandled.size() > 0 && !processingEarlyContent) {
PushProcessEarlyMessagesJob.enqueue(); PushProcessEarlyMessagesJob.enqueue();
} }
} }

View file

@ -51,7 +51,7 @@ public final class EarlyMessageCache {
} }
/** /**
* Returns a collection of all of the {@link ServiceMessageId}s referenced in the cache at the moment of inquiry. * Returns a collection of all of the {@link ServiceMessageId}s referenced in the cache at the moment of inquiry.
* Caution: There is no guarantee that this list will be relevant for any amount of time afterwards. * Caution: There is no guarantee that this list will be relevant for any amount of time afterwards.
*/ */
public synchronized @NonNull Collection<ServiceMessageId> getAllReferencedIds() { public synchronized @NonNull Collection<ServiceMessageId> getAllReferencedIds() {