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


##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java:
##########
@@ -711,6 +747,53 @@ protected void doAggregationComplete(
         }
     }
 
+    /**
+     * Adds the answer to the repository. If the repository keeps the answer, 
the answer takes over what the aggregated
+     * exchanges hold (such as a reference to a spooled stream cache), so it 
is released when the group is done with.
+     */
+    private void doAggregationRepositoryAddAndHandover(
+            String key, Exchange originalExchange, Exchange newExchange, 
Exchange answer) {
+        // the answer is not yet visible to other threads
+        handoverCompletions(newExchange, answer);
+        boolean keeping = isKeepingReferences();
+        // otherwise release after the add, as a persistent repository reads 
the body when it stores the exchange
+        List<Synchronization> release = keeping ? null : 
answer.getExchangeExtension().handoverCompletions();

Review Comment:
   This hands over and then runs every sync on the answer, including the ones 
the `AggregationStrategy` added. `ZipAggregationStrategy` (line ~225) and 
`TarAggregationStrategy` (line ~190) do `answer = newExchange; 
answer.addOnCompletion(new DeleteZipFileOnCompletion(zipFile))` on the first 
message. With `optimisticLocking()` or a JDBC/LevelDB repository, the temp zip 
is now deleted right after the first add, and the next message appends to a 
file that no longer exists. On main that completion was lost (a temp-file leak, 
but correct output).
   
   Suggestion: track only the syncs the aggregator creates. Right after 
`sc.copy(copy)`, `copy.getExchangeExtension().handoverCompletions()` returns 
exactly the stream-cache release sync(s), since the copy had none before. Keep 
those in an aggregator-owned holder carried with the group, and release only 
those, leaving strategy-added completions alone.



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