ammachado opened a new pull request, #30470:
URL: https://github.com/apache/camel/pull/30470

   # Description
   
   [CAMEL-27264](https://issues.apache.org/jira/browse/CAMEL-27264): files 
polled with `pollEnrich` (sftp, `bridgeErrorHandler=true`) stay in the 
endpoint's in-progress repository and are skipped by every later poll until a 
restart.
   
   **Root cause.** With `bridgeErrorHandler=true`, a read lock that fails (in 
the report, `Pipe closed` because another thread closed the sftp channel) 
bridges an error exchange into `GenericFilePollingConsumer.process`, and the 
file is not started. Since CAMEL-25930 the receive call keeps that exchange in 
its per-thread slot to return it. But no file was polled, so `doReceive` polled 
again within the `pollEnrich` timeout, found the file, and, with the slot 
already taken, put the file exchange on the queue of 
`EventDrivenPollingConsumer`. Nothing takes exchanges from that queue any more, 
so the `GenericFileOnCompletion` of the file never ran: the file stayed in 
progress for good, and nothing was logged above TRACE.
   
   The reporter's reproducer (sftp + JMS request-reply, attached to the ticket) 
was instrumented with a tracking in-progress repository: every stuck file has a 
last `add` in `pollDirectory` on the polling thread and no `remove` on any 
thread.
   
   **Fix** (`GenericFilePollingConsumer` only):
   
   1. `doReceive` does not poll again once the poll delivered an exchange to 
the calling receive call (such as the bridged error). The file is aborted as 
before and is picked up by the next poll.
   2. An exchange that arrives while the receive call of the same thread 
already has the exchange it returns is no longer queued: it is completed as 
failed, so a polled file is rolled back (left in place, removed from the 
in-progress repository) and polled again. Without the exception it would be 
committed (moved) without having been routed.
   
   Exchanges that arrive on a thread with no receive call in progress (for 
example a commit error bridged from another thread) still go to the queue as 
before; that is left for a follow-up.
   
   **Tests.** `FilePollEnrichBridgeErrorHandlerInProgressTest` (camel-core, 
local `file:` endpoint, no sftp or JMS needed):
   - a read lock that fails once: fails on main (`in-progress ... expected: <0> 
but was: <1>`), passes with fix 1;
   - a poll strategy that retries the poll after the error was delivered: fails 
with fix 1 alone, passes with fix 2.
   
   Also run locally: the camel-core `component.file` and `processor.enricher` 
tests and `*PollEnrich*Test` (641 tests, 0 failures), the camel-file module 
tests, and the camel-ftp `*PollEnrich*IT` (FTP and SFTP).
   
   Backport: CAMEL-25930 is in 4.22.3 and 4.18.6, so the same change applies to 
`camel-4.22.x` and `camel-4.18.x`.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes. (Built `components/camel-file` 
with `-Dquickly` and ran `formatter:format impsort:sort` on camel-file and 
camel-core; `git status` is clean. Not a build from the root folder.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


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