Croway opened a new pull request, #30176: URL: https://github.com/apache/camel/pull/30176
[CAMEL-27018](https://issues.apache.org/jira/browse/CAMEL-27018) ### What was wrong A follow-up of CAMEL-27001 (#30093), which made the producer stop use `RemoteFileOperations.disconnectOnStop()`. The consumer can hang the same way: its poll thread holds the `SftpOperations` lock for the whole `retrieveFile()`. When a download hangs because the server stopped answering, the forced shutdown stops the consumer, and the stop of the scheduler interrupts the poll: the download fails, but with `stepwise=true` (the default) the `finally` of the retrieval then changes back to the directory it started from (`changeBackToDirectory()`), which sends requests to the same server and waits as well, with the lock. `RemoteFileConsumer.doStop()` then called `disconnect()`, whose `SftpOperations.isConnected()` waits for that lock without a timeout, so `CamelContext.stop()` waited until the server answered again. It depends on the interrupts: a consumer on its own scheduled pool is interrupted twice (cancel, then `shutdownNow` of the pool), and the second interrupt usually, not always, ends the change of directory too; a consumer on a shared pool (`scheduledExecutorService` option) is interrupted once and always hangs. ### The fix `RemoteFileConsumer.doStop()` now calls `getOperations().disconnectOnStop()`, as `RemoteFileProducer.doStop()` does. For `SftpOperations` this waits for the lock while the shutdown is not forced, and disconnects the JSch session without it once forced, so the change of directory fails and the poll releases the lock. For FTP/FTPS and the other `RemoteFileOperations`, the default `disconnectOnStop()` is what `disconnect()` did (`isConnected()`, then `disconnect()`). The javadoc of `RemoteFileOperations.disconnectOnStop()` and `SftpOperations.disconnectOnStop()`, and the WARN of the forced disconnect, now mention the consumer. ### Tests `SftpConsumerStopDuringHungDownloadIT` (embedded SSHD whose SFTP subsystem blocks on the first read of file data, shutdown timeout 1 s): - `stopDoesNotWaitForDownloadOfConsumerOnSharedScheduledPool`: fails on main (`CamelContext.stop()` still waits after 20 s), passes with the fix. - `stopDoesNotWaitForDownloadWhenServerStopsAnswering` (the consumer's own pool): passed on main in the two runs (the second interrupt ended the change of directory), and passes with the fix. The unit tests of camel-ftp (198) and 228 ITs (all the sftp ITs, and the FTP `*Disconnect*`, `*Shutdown*`, `*Stop*`, `*Reconnect*` and `FtpConsumer*` ITs) pass. ### For reviewers - Same semantics as the producer: outside a forced shutdown (a route stopped with `stopRoute`, a graceful shutdown) the consumer stop still waits for the lock, as `disconnect()` did. - camel-mina-sftp reaches its own `disconnectOnStop()` through this change once CAMEL-27016 (separate PR) adds it; without it, it gets the default, which is the previous behaviour. - No upgrade guide entry: no option or default changes. _Claude Code on behalf of Croway_ -- 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]
