Improve robustness in receiving messages

This commit is contained in:
AsamK 2023-09-16 12:00:55 +02:00
parent e5aa10a730
commit a7744e837c
2 changed files with 48 additions and 36 deletions

View file

@ -137,13 +137,17 @@ public final class IncomingMessageHandler {
final Manager.ReceiveMessageHandler handler final Manager.ReceiveMessageHandler handler
) { ) {
final var actions = new ArrayList<HandleAction>(); final var actions = new ArrayList<HandleAction>();
SignalServiceContent content = null;
Exception exception = null;
try {
if (envelope.hasSourceServiceId()) { if (envelope.hasSourceServiceId()) {
// Store uuid if we don't have it already // Store uuid if we don't have it already
// uuid in envelope is sent by server // uuid in envelope is sent by server
account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress()); account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
} }
SignalServiceContent content = null; } catch (Exception e) {
Exception exception = null; exception = e;
}
if (!envelope.isReceipt()) { if (!envelope.isReceipt()) {
try { try {
final var cipherResult = dependencies.getCipher() final var cipherResult = dependencies.getCipher()

View file

@ -205,8 +205,12 @@ public class ReceiveHelper {
backOffCounter = 0; backOffCounter = 0;
if (returnOnTimeout) return; if (returnOnTimeout) return;
continue; continue;
} catch (Exception e) {
logger.error("Unknown error when receiving messages", e);
continue;
} }
try {
final var result = context.getIncomingMessageHandler().handleEnvelope(envelope, receiveConfig, handler); final var result = context.getIncomingMessageHandler().handleEnvelope(envelope, receiveConfig, handler);
for (final var h : result.first()) { for (final var h : result.first()) {
final var existingAction = queuedActions.get(h); final var existingAction = queuedActions.get(h);
@ -230,7 +234,8 @@ public class ReceiveHelper {
final var recipientId = account.getRecipientResolver() final var recipientId = account.getRecipientResolver()
.resolveRecipient(ACI.from(address.uuid().get())); .resolveRecipient(ACI.from(address.uuid().get()));
try { try {
cachedMessage[0] = account.getMessageCache().replaceSender(cachedMessage[0], recipientId); cachedMessage[0] = account.getMessageCache()
.replaceSender(cachedMessage[0], recipientId);
} catch (IOException ioException) { } catch (IOException ioException) {
logger.warn("Failed to move cached message to recipient folder: {}", logger.warn("Failed to move cached message to recipient folder: {}",
ioException.getMessage(), ioException.getMessage(),
@ -241,6 +246,9 @@ public class ReceiveHelper {
cachedMessage[0].delete(); cachedMessage[0].delete();
} }
} }
} catch (Exception e) {
logger.error("Unknown error when handling messages", e);
}
} }
} }