davsclaus commented on code in PR #28249:
URL: https://github.com/apache/camel/pull/28249#discussion_r4357671681
##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java:
##########
@@ -408,6 +409,12 @@ public boolean process(Exchange exchange, AsyncCallback
callback) {
if (variableReceive != null) {
try {
originalBody = exchange.getMessage().getBody();
+ // eagerly materialize a WrappedFile (e.g. GenericFile from a
file consumer) body
+ // into bytes so it can survive the file being moved/deleted
by GenericFileOnCompletion
+ // after the exchange completes, before any downstream code
reads the body
+ if (originalBody instanceof WrappedFile) {
+ originalBody = exchange.getMessage().getBody(byte[].class);
+ }
Review Comment:
This changes what every file route with `pollEnrich().variableReceive(...)`
sees, to fix a read that happens only after the exchange is done:
- the whole file is read into memory here (a 2 GB file becomes a 2 GB
`byte[]`), where before it stayed a lazy `GenericFile` that a downstream step
could stream;
- the body after the `pollEnrich` is a `byte[]` instead of a `GenericFile`.
A bean or processor that takes `File`, `GenericFile` or the file name from the
body behaves differently. This happens also when something was polled, because
`originalBody` is restored on every aggregation with `variableReceive`;
- a conversion failure (unreadable file) now fails the exchange in
`pollEnrich` itself.
The race is the same without `pollEnrich` (`from("file:...").to("mock:x")`
and then reading the body after completion), so I would keep `PollEnricher` as
it is. The test fix on main (0c1e85c8631c) reads the body on arrival instead.
--
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]