davsclaus commented on code in PR #27990:
URL: https://github.com/apache/camel/pull/27990#discussion_r4301786297


##########
components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java:
##########
@@ -266,10 +266,32 @@ public String toString() {
             // process the exchange
             processExchange(exchange);
         }
+        // the remaining exchanges are not routed as the consumer is stopping: 
their mails must be consumed by a
+        // later poll (or by another consumer sharing the idempotent 
repository)
+        releaseNotRouted(CastUtils.cast(exchanges));

Review Comment:
   Minor: the give-back runs only when the loop ends normally. If 
`processExchange` throws (rare, since routing errors normally land on the 
exchange, but for example a `RejectedExecutionException`), the rest of the 
batch keeps its keys again. Putting the loop in `try { ... } finally { 
releaseNotRouted(CastUtils.cast(exchanges)); }` would cover that path too.



##########
components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java:
##########
@@ -330,7 +352,15 @@ private Queue<Exchange> retrieveMessages() throws 
MessagingException {
                 if (getEndpoint().getConfiguration().isPeek()) {
                     peekMessage(message);
                 }
-                Exchange exchange = createExchange(new KeyValueHolder<>(key, 
message));
+                Exchange exchange;
+                try {
+                    exchange = createExchange(new KeyValueHolder<>(key, 
message));
+                } catch (Exception e) {

Review Comment:
   Minor: only `createExchange` is guarded. If 
`getIdempotentRepository().add(key)` in `isValidMessage` throws for a later 
mail (a JDBC/Infinispan/Redis repository that is briefly unavailable), the keys 
of the mails already in `answer` stay in the repository, which is the same 
leak. Putting the try/catch around the whole `for` loop body (and removing the 
current key only once it has been added) would cover that path too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to