[FIX] JamesMailSpooler should be more resilient on JVM Error
Upon JVM Error, the error would not be caught to be retried. Therefore, the message would not be acked -> RabbitMQ would disconnect the MailQueue consumer after the Delivery Acknowledgement Timeout.
For example, a custom mailet that depends on the old `javax` APIs caused `java.lang.NoSuchMethodError: 'javax.mail.internet.MimeMessage org.apache.mailet.Mail.getMessage()` that caused the RabbitMQ consumer being disconnected.
diff --git a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
index 61b2256..3fb639c 100644
--- a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
+++ b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
@@ -138,14 +138,14 @@
throw new InterruptedException("Thread has been interrupted");
}
queueItem.done(MailQueueItem.CompletionStatus.SUCCESS);
- } catch (Exception e) {
+ } catch (Throwable e) {
handleError(queueItem, mail, originalRecipients, e);
} finally {
LOGGER.debug("==== End processing mail {} ====", mail.getName());
}
}
- private void handleError(MailQueueItem queueItem, Mail mail, ImmutableList<MailAddress> originalRecipients, Exception processingException) {
+ private void handleError(MailQueueItem queueItem, Mail mail, ImmutableList<MailAddress> originalRecipients, Throwable processingException) {
int failureCount = computeFailureCount(mail);
// Restore original recipients
@@ -184,7 +184,7 @@
queueItem.done(MailQueueItem.CompletionStatus.SUCCESS);
}
- private void nack(MailQueueItem queueItem, Exception processingException) {
+ private void nack(MailQueueItem queueItem, Throwable processingException) {
try {
queueItem.done(MailQueueItem.CompletionStatus.REJECT);
} catch (MailQueue.MailQueueException ex) {