allthingssecurity opened a new pull request, #30841: URL: https://github.com/apache/camel/pull/30841
# Description [CAMEL-27477](https://issues.apache.org/jira/browse/CAMEL-27477) Producer health checks are off by default; this only matters with `camel.health.producersEnabled=true`. The health check of an ftp, ftps or sftp producer (`RemoteFileProducerHealthCheck`) calls `doPreWriteCheck(exchange, true)`, which sends a `NOOP` through `RemoteFileOperations.sendNoop()`. Since CAMEL-27214 each operation of `FtpOperations` holds one lock, as `SftpOperations` and `MinaSftpOperations` already did, and an upload holds it for the whole transfer. So the check waited until the upload ended. `AbstractHealthCheck.call` holds the lock of the check while it runs, with no deadline, so every further readiness call waited behind it, and its thread stayed blocked after the caller gave up (a Kubernetes readiness probe gives up after 1 s by default). During each long upload to a healthy server the application was reported not ready, and the probe threads piled up until the upload ended. On a server that stops taking data during an upload, the wait lasts as long as the upload hangs, which `soTimeout` does not bound for a blocked write. Change: - new default method `RemoteFileOperations.runIfIdle(check)`, which runs the check and returns `true`. `FtpOperations` (also used by ftps), `SftpOperations` and `MinaSftpOperations` implement it with `tryLock()`: the check runs only when no other thread holds the lock of the operations, and holds it while it runs (the lock is reentrant), so an upload that starts meanwhile waits for the check: the `NOOP`, and the connect when the `NOOP` failed, which it already waited for one after the other before; - `RemoteFileProducerHealthCheck` runs `doPreWriteCheck` through it. When the connection is in use, it sends no `NOOP` and does not connect: it reports the state that its last check of the connection found (`UP` before the first one), with the message "FtpProducer is busy, the connection is in use" and the detail `busy=true`. The next call checks the connection again when it is no longer in use. This is what the check of a polling consumer does for a long poll: a long transfer alone is not a failure. CAMEL-26998 also gave polling consumers an opt-in bound (`healthCheckMaxPollDuration`: DOWN while a poll runs longer than that); the producer gets no such option here, see the second point under "Not changed"; - upgrade guide 4.24: a short entry, as readiness output changes during an upload, and an upload that hangs no longer shows as not ready. The other implementations of `RemoteFileOperations` (scp, Azure Files) keep the default, which runs the check as before. Not changed here: - on an idle connection to a server that does not answer, the `NOOP` of the check still waits up to `soTimeout`, and so do the readiness calls behind it; with `soTimeout=0` that wait has no end. Lowering `soTimeout` is the documented answer (see "About timeouts" on the FTP page); a deadline for health checks in general would be a camel-health change; - an upload that hangs (a server or network that stops taking data) keeps the connection busy until the upload fails. `soTimeout` and `timeout` bound reads, not a blocked write, so that can last until TCP or the SSH session gives up. For all that time the check reports its last state, normally UP, with `busy=true`; before, the readiness call waited for the upload and timed out, so the probe saw not ready. After the upload fails, the next check connects again or reports DOWN. A bound like `healthCheckMaxPollDuration` for producers (DOWN when the connection is busy longer than a set time) would be a new endpoint option, so it is not part of this fix; - the checks of two producers to the same host share one id (`producer:ftp-<host>`): stopping one can remove the check of the other. 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, so that with `sendNoop=false` the next upload fails once (low; needs `sendNoop=false`). A probe can also connect again over a connection that the route has just opened, or after the producer stopped, in narrow windows. These are left as they are. Tests: - new `FtpProducerHealthCheckDuringUploadTest` (embedded FTP server, as the other camel-ftp tests): after a small upload, readiness is UP; then an upload whose body stops half way (latch) until the test lets it go on. Three readiness calls made in parallel during the upload must each answer within 5 s, UP with `busy=true`; after the upload, the check sends the `NOOP` again (UP, no `busy`); - new `SftpProducerHealthCheckDuringUploadIT` (camel-ftp) and `MinaSftpProducerHealthCheckDuringUploadIT` (camel-mina-sftp): the same against the embedded SFTP server; - new `RemoteFileProducerHealthCheckBusyTest` (mocked operations): a check that finds the server refusing the connection is DOWN; while busy it stays DOWN with `busy=true` and does not connect; after a check that connects it is UP, and UP with `busy=true` while busy. Without the change, `FtpProducerHealthCheckDuringUploadTest`, `SftpProducerHealthCheckDuringUploadIT` and `MinaSftpProducerHealthCheckDuringUploadIT` fail: no readiness call answers within 5 s during the upload (`TimeoutException`). `RemoteFileProducerHealthCheckBusyTest` uses the new method, so it does not compile without the change. With it the camel-ftp unit tests pass (290 run, 0 failures, 9 skipped) and so do the camel-mina-sftp unit tests (53 run, 0 failures, 1 skipped). The new classes passed 20 of 20 runs each (the two SFTP ITs run locally with the JUnit launcher against the embedded SFTP server; CI runs them as ITs). The change merges cleanly with main and with the branch of the sibling ticket (the check id); 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: candidate for 4.x lines that have CAMEL-27214 (the FTP lock); on older lines only the SFTP producer waits this way. The new interface method has a default, so other implementations are not affected. # 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-27477](https://issues.apache.org/jira/browse/CAMEL-27477). # 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, camel-mina-sftp and the core modules with the formatter and import-sort plugins and ran their 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]
