shashank created CAMEL-27214:
--------------------------------

             Summary: camel-ftp - the delete or move of a file that the route 
handed over to another thread (seda) runs on the connection of the consumer 
while the consumer uses it
                 Key: CAMEL-27214
                 URL: https://issues.apache.org/jira/browse/CAMEL-27214
             Project: Camel
          Issue Type: Bug
          Components: camel-ftp
            Reporter: shashank
            Assignee: shashank


h3. What happens

The commit of a consumed file ({{delete=true}}, {{move}}, {{moveFailed}}) runs 
when the exchange is done, on the connection of the consumer. When the route 
hands the exchange over to another thread, as {{to("seda:...")}} does for an 
{{InOnly}} exchange (the on completions go with the copy), the delete or rename 
runs on the seda thread, while the ftp consumer goes on with the next file of 
the poll (RETR) or with the next poll (stepwise CWD, LIST). {{FtpOperations}} 
has no lock, and an FTP control connection runs one command at a time, so the 
commands and replies of the two threads mix:

* a thread reads the reply to the command of the other thread: a download, a 
listing or the delete fails, or a reply such as the one to PASV cannot be 
parsed;
* with {{stepwise=true}} (the default) the delete reads the current directory 
while the next poll is in the directory of the files, changes to the directory 
of the file from there, and fails: the file stays on the server, its 
in-progress entry is removed, and the next poll consumes it again (a 
duplicate), at every poll where the commit and the walk overlap.

{{SftpOperations}} holds a lock in every operation since CAMEL-8887 (same 
report for sftp + seda); ftp and ftps never got it.

h3. How to reproduce

{{FtpConsumerCommitOnOtherThreadTest}} (camel-ftp, in-JVM fake FTP server): 
{{delete=true}} and {{to("seda:work")}}; the seda thread sends the delete 
commands of the first file while the consumer downloads the second one, and 
while the next poll lists the directory (stepwise), where the delete fails and 
the file is consumed again.

h3. Fix

Each operation of {{FtpOperations}} (and the connect of {{FtpsOperations}}) 
holds a lock, as {{SftpOperations}} does, and the walk of the consumer through 
the directories ({{pollDirectory}}) holds it from the first change of directory 
to the change back. The disconnect when the consumer stops does not take the 
lock, so a stop still ends an operation that the server does not answer 
(CAMEL-26999).

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to