allthingssecurity opened a new pull request, #30842: URL: https://github.com/apache/camel/pull/30842
# Description [CAMEL-27478](https://issues.apache.org/jira/browse/CAMEL-27478) Producer health checks are off by default; this only matters with `camel.health.producersEnabled=true`. The id of the health check of an ftp, ftps or sftp producer was `"producer:ftp-" + host` (`RemoteFileProducerHealthCheck`), and `AbstractHealthCheck.equals` compares the id only. Two producers to the same host got the same id: two routes that write into different directories of one server, the producers of a `toD`, or the instances of one endpoint (the producer is not a singleton, so a route with concurrent exchanges can have several). The registry keeps only the first check of an id when it calls the checks, so only one of these producers was checked. When one of them stopped, `removeHealthCheck` removed the first equal check, which could belong to a producer that was still running. The check left behind belonged to the stopped producer: each readiness call then ran `doPreWriteCheck` on it, which connected it again. Nothing closed that connection (its stop had already run), and the probe opened it again whenever the server dropped it, while the running producer was no longer chec ked. Change: - the id also names the endpoint, as the AWS producer checks do with the endpoint id: `producer:ftp-<host>-<endpoint id>`, for example `producer:ftp-myhost-endpoint7`, and `-2`, `-3`, ... after it for the other producers of an endpoint that has more than one at a time; - `RemoteFileEndpoint` keeps the numbers in use (a concurrent set). A producer takes the lowest number that no started producer of its endpoint uses when it starts, and gives it back after it removed its check when it stops. So a single producer keeps the same id when its route is stopped and started, and a new pooled instance reuses a free number. The endpoint id itself is a counter given when the endpoint is created (`endpoint1`, `endpoint2`, ...), so an endpoint created again, for example after a route reload, has a new id, as with the AWS checks; - the id still has no user name or password: CAMEL-24717 shows why the endpoint URI is not used (FTP URIs carry the password, and the user name is in the authority); - the mina-sftp, scp and Azure Files producers extend the same producer and get the same ids; - the public constructor `RemoteFileProducerHealthCheck(producer)` stays and gives the id of the first producer of the endpoint; - upgrade guide 4.24: the id changed. A configuration that named the old id should use a pattern such as `producer:ftp-myhost-*` (the endpoint id can change, so an exact new id is not a good key). Readiness now checks each started producer, one `NOOP` each, where it checked one per host before; that matters for a `toD` that writes into many directories of one server. Not changed here: - a probe already running when a producer stops can still connect it once (narrow window: the stop removes the check, but does not wait for a call in progress); - the producer check waits for an upload in progress on the connection; that has its own ticket and pull request; - a probe that connects again can leave the `loggedIn` flag of the producer `true` while the route closes that connection (low; needs `sendNoop=false`), and can connect again over a connection that the route has just opened (narrow window). These are left as they are. Tests, new `FtpProducerHealthCheckIdTest` (embedded FTP server, as the other camel-ftp tests; exposure level `full`, so that readiness returns the result of every check; no sleep): - `eachProducerHasItsOwnCheck`: routes a and b write to `/a` and `/b` of one server; readiness calls both checks, with ids that name each endpoint and contain no credentials; - `stoppingOneProducerKeepsTheCheckOfTheOther`: send to b, then to a (so b's check comes first), stop route a and wait until the server has one session; after a readiness call the server still has one session (the stopped producer of a was not connected again), and the only producer check left is b's, UP; - `producersOfOneEndpointHaveTheirOwnCheck`: two producers of one endpoint get `<id>` and `<id>-2`; after the first stops, only `<id>-2` is left; a third producer takes `<id>` again. Without the change all three tests fail: two producers to one host give one check (`[producer:ftp-localhost]`), the readiness call connects the stopped producer of route a (2 sessions instead of 1), and the producers of one endpoint have no checks with an id of their own. With it the camel-ftp unit tests pass (291 run, 0 failures, 9 skipped), and the new class passes 20 of 20 runs. The change merges cleanly with main and with the branch of the sibling ticket (the check that waits for an upload); with both merged on current main (which has CAMEL-27277), the camel-ftp unit tests (293 run, 0 failures, 9 skipped) and the camel-mina-sftp unit tests (53 run, 0 failures, 1 skipped) pass, and the new tests of both branches pass 20 of 20 runs. Backport: the id change is visible to users who name the id, so main only, unless a maintenance line wants the fix with an upgrade note. # 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): [CAMEL-27478](https://issues.apache.org/jira/browse/CAMEL-27478). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built camel-ftp-common, camel-ftp and the core modules with the formatter and import-sort plugins and ran the camel-ftp unit tests. I did not run the full root build.) # 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. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
