allthingssecurity commented on code in PR #27671:
URL: https://github.com/apache/camel/pull/27671#discussion_r4240520036


##########
components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConsumer.java:
##########
@@ -91,17 +95,41 @@ protected int poll() throws Exception {
         forceConsumerAsReady();
 
         if (c.getMessages() != null) {
-            for (Message message : c.getMessages()) {
-                Message mess
-                        = getClient().users().messages().get("me", 
message.getId()).setFormat(messageFormat()).execute();
-                Exchange exchange = 
createExchange(getEndpoint().getExchangePattern(), mess);
-                answer.add(exchange);
+            try {
+                for (Message message : c.getMessages()) {
+                    addExchange(message.getId(), answer);
+                }
+            } catch (Exception e) {
+                // none of the messages of this poll is processed
+                releaseInProgress(answer);
+                throw e;
             }
         }
 
         return processBatch(CastUtils.cast(answer));
     }
 
+    private void addExchange(String id, Queue<Exchange> answer) throws 
Exception {
+        // skip the message if an exchange of a previous poll is still 
processing it
+        if (!inProgress.add(id)) {

Review Comment:
   Confirmed and fixed in c31224e63271, with the suggested shape: 
`Set.copyOf(inProgress)` is taken before
   `request.execute()` (`GoogleMailStreamConsumer.java:95`) and `addExchange` 
skips an id that is in the snapshot or
   already in progress (line 119). New test 
`messageCompletedAfterTheListingIsNotConsumedAgain`: the fake Gmail transport
   holds the listing response until the in-flight exchange has completed 
(marked as read, id released), gated on its
   `ExchangeCompletedEvent`, no sleeps. Against the previous commit `m1` is got 
twice (`expected: <1> but was: <2>`), now
   once. The snapshot is per poll, so nothing is skipped for longer than one 
poll: with `markAsRead=false`, or after a
   failed exchange, a message that was in flight when the poll started is 
consumed by the next poll instead of this one.
   The exchanges that are never routed (stopping consumer, failed poll) are now 
also released to the exchange factory
   (line 137). Module suite: 49 tests, 0 failures (17 integration tests 
skipped, they need credentials).
   
   _Claude Code on behalf of allthingssecurity_



-- 
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