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

   [CAMEL-27016](https://issues.apache.org/jira/browse/CAMEL-27016)
   
   ### What was wrong
   
   The same as CAMEL-27001 (#30093) for camel-sftp, in camel-mina-sftp. 
`MinaSftpOperations` runs every operation under one `ReentrantLock`, and 
`storeFile()` holds it for the whole upload, whose stream waits for the 
acknowledgement of each write up to the Apache MINA SSHD idle timeout (10 
minutes by default). `RemoteFileProducer.doStop()` calls 
`RemoteFileOperations.disconnectOnStop()`, which `MinaSftpOperations` did not 
override: the default `isConnected()` waits for the lock without a timeout, so 
`CamelContext.stop()` did not return while an upload to a server that stopped 
answering hung, also after the shutdown timeout.
   
   ### The fix
   
   `MinaSftpOperations.disconnectOnStop()`, with the semantics of 
`SftpOperations.disconnectOnStop()`:
   
   - while the shutdown is not forced, it waits for the lock as before (a 
healthy but slow upload: a producer cache that evicts the producer, 
`ProducerTemplate.stop()`, a graceful shutdown), checking 
`ShutdownStrategy.isForceShutdown()` every second;
   - once the shutdown is forced, it closes the session at once without the 
lock (`ClientSession.close(true)`): the SFTP channel closes and 
`DefaultSftpClient` cancels the requests that wait for an answer, so the upload 
fails and releases the lock. It then takes the lock (up to 1 s) to 
`disconnect()` as before, which stops the `SshClient` and its threads;
   - a connect in progress is waited for (`connecting` flag, as in 
`SftpOperations`).
   
   `session` is now `volatile`, as it is read without the lock.
   
   ### Tests
   
   `MinaSftpProducerStopDuringHungUploadIT`, mirroring 
`SftpProducerStopDuringHungUploadIT` (embedded SSHD whose SFTP subsystem blocks 
on the first write):
   
   - `stopDoesNotWaitForUploadWhenServerStopsAnswering` and 
`stopDoesNotWaitForUploadOfRouteWhoseConsumerStopsRightAway`: fail on main 
(`CamelContext.stop()` still waits after 20 s), pass with the fix; the upload 
fails.
   - `gracefulStopWaitsForUploadOfRouteWhoseConsumerStopsRightAway` and 
`stopOutsideForcedShutdownWaitsForUpload`: outside a forced shutdown the stop 
waits and the upload completes (pass before and after).
   
   The unit tests (53) and all the ITs (314 + 24 serial) of camel-mina-sftp 
pass.
   
   ### For reviewers
   
   - The half-open variant of the camel-sftp IT (an upload blocked writing to a 
socket that the server no longer reads) is not ported: Apache MINA SSHD writes 
through asynchronous NIO2 channels, so the upload waits for acknowledgements 
rather than in a socket write, but that case is not covered by a test.
   - The consumer of camel-mina-sftp reaches this method too once CAMEL-27018 
(#30176, the consumer stop of camel-sftp) makes `RemoteFileConsumer.doStop()` 
call `disconnectOnStop()`.
   - 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]

Reply via email to