You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/03/29 03:11:50 UTC
(james-project) branch master updated (8155100e36 -> 4fcec50de0)
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
from 8155100e36 JAMES-3977 IMAP log should embed username where possible
new cc87df53ad [FIX] JamesMailSpooler should be more resilient on JVM Error
new f748eb53b3 Add mailet processing tests for `NoSuchMethodError`
new 4fcec50de0 [FIX] `onMailetException` should catch jvm Error
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/james/mailets/MailetErrorsTest.java | 86 ++++++++++++++++++++++
.../NoSuchMethodErrorMailet.java} | 6 +-
.../mailetcontainer/impl/JamesMailSpooler.java | 6 +-
.../james/mailetcontainer/impl/ProcessorImpl.java | 2 +-
4 files changed, 93 insertions(+), 7 deletions(-)
copy server/mailet/integration-testing/src/test/java/org/apache/james/{transport/mailets/RuntimeErrorMailet.java => mailets/NoSuchMethodErrorMailet.java} (91%)
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
(james-project) 01/03: [FIX] JamesMailSpooler should be more resilient on JVM Error
Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit cc87df53ad41fa13c04ff9c9946aff7b2091cddf
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Wed Mar 27 10:53:37 2024 +0700
[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.
---
.../org/apache/james/mailetcontainer/impl/JamesMailSpooler.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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 61b2256ddc..3fb639c26d 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 @@ public class JamesMailSpooler implements Disposable, Configurable, MailSpoolerMB
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 @@ public class JamesMailSpooler implements Disposable, Configurable, MailSpoolerMB
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) {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
(james-project) 02/03: Add mailet processing tests for `NoSuchMethodError`
Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit f748eb53b38954ad26c0f5adc4f7c1512bd255f6
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Thu Mar 28 11:29:15 2024 +0700
Add mailet processing tests for `NoSuchMethodError`
The error could be thrown upon an extension mailet relying on old James's API.
Today James mailet pipeline is not resilient on that error, we should be more resilient on that.
Add tests for 3 cases of `onMailetException`:
- default: should trigger error processor
- propagate: propagate error to `JamesMailSpooler`
- ignore: error should be ignored
---
.../org/apache/james/mailets/MailetErrorsTest.java | 86 ++++++++++++++++++++++
.../james/mailets/NoSuchMethodErrorMailet.java | 32 ++++++++
2 files changed, 118 insertions(+)
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
index dc1d65fee5..7f1573225e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
@@ -19,6 +19,7 @@
package org.apache.james.mailets;
+import static org.apache.james.MailsShouldBeWellReceived.CALMLY_AWAIT;
import static org.apache.james.MemoryJamesServerMain.SMTP_ONLY_MODULE;
import static org.apache.james.mailets.configuration.CommonProcessors.ERROR_REPOSITORY;
import static org.apache.james.mailets.configuration.CommonProcessors.rrtError;
@@ -60,6 +61,7 @@ import org.apache.james.transport.matchers.RecipientIs;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.MailRepositoryProbeImpl;
import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SpoolerProbe;
import org.apache.james.utils.TestIMAPClient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
@@ -131,6 +133,59 @@ class MailetErrorsTest {
awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
}
+ @Test
+ void mailSpoolerShouldWellHandleNoSuchMethodErrorWhenPropagateOnMailetException(@TempDir File temporaryFolder) throws Exception {
+ jamesServer = TemporaryJamesServer.builder()
+ .withBase(SMTP_ONLY_MODULE)
+ .withMailetContainer(MailetContainer.builder()
+ .putProcessor(CommonProcessors.deliverOnlyTransport())
+ .putProcessor(ProcessorConfiguration.error()
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(ToRepository.class)
+ .addProperty("repositoryPath", CUSTOM_REPOSITORY.asString())))
+ .putProcessor(ProcessorConfiguration.root()
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(NoSuchMethodErrorMailet.class)
+ .addProperty("onMailetException", "propagate"))))
+ .withSmtpConfiguration(SmtpConfiguration.builder()
+ .withAutorizedAddresses("0.0.0.0/0.0.0.0"))
+ .build(temporaryFolder);
+ jamesServer.start();
+ MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
+
+ smtpMessageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()).sendMessage(FROM, FROM);
+
+ awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
+ }
+
+ @Test
+ void noSuchMethodErrorShouldTriggerErrorProcessorWhenDefaultOnMailetException(@TempDir File temporaryFolder) throws Exception {
+ jamesServer = TemporaryJamesServer.builder()
+ .withBase(SMTP_ONLY_MODULE)
+ .withMailetContainer(MailetContainer.builder()
+ .putProcessor(CommonProcessors.deliverOnlyTransport())
+ .putProcessor(ProcessorConfiguration.error()
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(ToRepository.class)
+ .addProperty("repositoryPath", CUSTOM_REPOSITORY.asString())))
+ .putProcessor(ProcessorConfiguration.root()
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(NoSuchMethodErrorMailet.class))))
+ .withSmtpConfiguration(SmtpConfiguration.builder()
+ .withAutorizedAddresses("0.0.0.0/0.0.0.0"))
+ .build(temporaryFolder);
+ jamesServer.start();
+ MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
+
+ smtpMessageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()).sendMessage(FROM, FROM);
+
+ awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
+ }
+
@Test
void propagateShouldAllowReprocessing(@TempDir File temporaryFolder) throws Exception {
jamesServer = TemporaryJamesServer.builder()
@@ -482,6 +537,37 @@ class MailetErrorsTest {
awaitAtMostOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
}
+ @Test
+ void onExceptionIgnoreShouldContinueProcessingWhenNoSuchMethodError(@TempDir File temporaryFolder) throws Exception {
+ jamesServer = TemporaryJamesServer.builder()
+ .withBase(SMTP_ONLY_MODULE)
+ .withMailetContainer(MailetContainer.builder()
+ .putProcessor(CommonProcessors.deliverOnlyTransport())
+ .putProcessor(errorProcessor())
+ .putProcessor(ProcessorConfiguration.root()
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(NoSuchMethodErrorMailet.class)
+ .addProperty("onMailetException", "ignore"))
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(ToRepository.class)
+ .addProperty("repositoryPath", CUSTOM_REPOSITORY.asString()))))
+ .withSmtpConfiguration(SmtpConfiguration.builder()
+ .withAutorizedAddresses("0.0.0.0/0.0.0.0"))
+ .build(temporaryFolder);
+ jamesServer.start();
+
+ smtpMessageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()).sendMessage(FROM, FROM);
+
+ CALMLY_AWAIT.until(() -> jamesServer.getProbe(SpoolerProbe.class).processingFinished());
+
+ awaitAtMostOneMinute.until(() -> jamesServer.getProbe(MailRepositoryProbeImpl.class)
+ .getRepositoryMailCount(ERROR_REPOSITORY) == 0);
+ awaitAtMostOneMinute.until(() -> jamesServer.getProbe(MailRepositoryProbeImpl.class)
+ .getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
+ }
+
@Test
void onExceptionIgnoreShouldContinueProcessingWhenMessagingException(@TempDir File temporaryFolder) throws Exception {
jamesServer = TemporaryJamesServer.builder()
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NoSuchMethodErrorMailet.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NoSuchMethodErrorMailet.java
new file mode 100644
index 0000000000..53fe9602a1
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NoSuchMethodErrorMailet.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailets;
+
+import jakarta.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+public class NoSuchMethodErrorMailet extends GenericMailet {
+ @Override
+ public void service(Mail mail) throws MessagingException {
+ throw new NoSuchMethodError();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
(james-project) 03/03: [FIX] `onMailetException` should catch jvm Error
Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4fcec50de01752a8ed0c78ef1f81b16b83658a7d
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Thu Mar 28 11:33:20 2024 +0700
[FIX] `onMailetException` should catch jvm Error
`onMailetException` has had no impact upon `NoSuchMethodError`.
---
.../main/java/org/apache/james/mailetcontainer/impl/ProcessorImpl.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorImpl.java b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorImpl.java
index 617f61d3fa..57c8fc17b7 100644
--- a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorImpl.java
+++ b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorImpl.java
@@ -79,7 +79,7 @@ public class ProcessorImpl {
.build()) {
MailetPipelineLogging.logBeginOfMailetProcess(mailet, mail);
mailet.service(mail);
- } catch (Exception | NoClassDefFoundError me) {
+ } catch (Throwable me) {
ex = me;
String onMailetException = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org