[jira] [Created] (NET-419) Not possible to call FTPClient.abort() method correctly

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)
Not possible to call FTPClient.abort() method correctly
-------------------------------------------------------

                 Key: NET-419
                 URL: https://issues.apache.org/jira/browse/NET-419
             Project: Commons Net
          Issue Type: Bug
          Components: FTP
    Affects Versions: 3.0
         Environment: java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

            Reporter: Tomas Mysik


Unfortunately, it seems that there are difficulties of using FTPClient.abort()
method [1][2]. Also, it is really not clear how the abort() method should be
called/used at all - if from another thread (as I would expect) then there is a problem with
thread-safety: FTPClient itself is not thread-safe so it means that some
custom lock/monitor must be used; but this lock will prevent calling abort() on
the FTPClient while it is downloading/uploading file since file upload/download
itself is blocking...

If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.

Thanks a lot.
[1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
[2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/NET-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094555#comment-13094555 ]

Tomas Mysik commented on NET-419:
---------------------------------

ping

> Not possible to call FTPClient.abort() method correctly
> -------------------------------------------------------
>
>                 Key: NET-419
>                 URL: https://issues.apache.org/jira/browse/NET-419
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: java version "1.6.0_26"
> Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
> Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Tomas Mysik
>
> Unfortunately, it seems that there are difficulties of using FTPClient.abort()
> method [1][2]. Also, it is really not clear how the abort() method should be
> called/used at all - if from another thread (as I would expect) then there is a problem with
> thread-safety: FTPClient itself is not thread-safe so it means that some
> custom lock/monitor must be used; but this lock will prevent calling abort() on
> the FTPClient while it is downloading/uploading file since file upload/download
> itself is blocking...
> If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.
> Thanks a lot.
> [1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
> [2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/NET-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13096681#comment-13096681 ]

Bogdan Drozdowski commented on NET-419:
---------------------------------------

 No need to ping us. We see your message. We may not reply immediately, but your issue is still open.
 The problem is that it's not that easy just to provide thread-safety. If the methods are synchronized, you won't be able to call abort() when another method is executing (like retrieveFile()).
 Perhaps just command sending should be synchronized (to synchronize the input/output buffers), but that won't always solve the problem, because some commands (like file send/retrieve) have two replies and the client needs to wait for the second one, so it needs to be in the synchronized block while the operation you want to abort is being performed. Right now we dont' have synchronized blocks, so you can call abort() at any time (and mostly it will work). If we had everything synchronized, you wouldn't be able to call abort() during the operation at all. So even if the current solution is not perfect, the synchronized solution is even worse. This needs a re-think of what should be done.

> Not possible to call FTPClient.abort() method correctly
> -------------------------------------------------------
>
>                 Key: NET-419
>                 URL: https://issues.apache.org/jira/browse/NET-419
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: java version "1.6.0_26"
> Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
> Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Tomas Mysik
>
> Unfortunately, it seems that there are difficulties of using FTPClient.abort()
> method [1][2]. Also, it is really not clear how the abort() method should be
> called/used at all - if from another thread (as I would expect) then there is a problem with
> thread-safety: FTPClient itself is not thread-safe so it means that some
> custom lock/monitor must be used; but this lock will prevent calling abort() on
> the FTPClient while it is downloading/uploading file since file upload/download
> itself is blocking...
> If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.
> Thanks a lot.
> [1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
> [2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/NET-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13097040#comment-13097040 ]

Tomas Mysik commented on NET-419:
---------------------------------

> No need to ping us. We see your message. We may not reply immediately, but your issue is still open.

Sorry, I did it since the issue is still unassigned (in NetBeans, this means that the issue is not yet evaluated).

> The problem is [...]

Yes, exactly as I wrote it in my initial description. That's the reason why I have reported this issue and I'm glad that I'm not the only one who doesn't know how to use this method properly.

> you can call abort() at any time (and mostly it will work)

Unfortunately, this is likely not acceptable for us, I'm afraid. In such case, sooner or later I would get a bug report and I won't be able to fix it so I prefer not to provide this functionality at all.

> This needs a re-think of what should be done.

I don't know your code but have seen that you are able to keep-alive during file transfer via repeatedly sending NOOP command after reading some chunk of data, right? As a quick, not-so-great fix - what about to add a volatile [1] boolean field transferAborted and check this field during file transfer as well?

Thanks a lot.
[1] Yes, I know that "sudden" use of volatile in not thread-safe code can be confusing; but, with a proper comment (with reference to this bug perhaps) added to such field, I think that it would be acceptable.


> Not possible to call FTPClient.abort() method correctly
> -------------------------------------------------------
>
>                 Key: NET-419
>                 URL: https://issues.apache.org/jira/browse/NET-419
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: java version "1.6.0_26"
> Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
> Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Tomas Mysik
>
> Unfortunately, it seems that there are difficulties of using FTPClient.abort()
> method [1][2]. Also, it is really not clear how the abort() method should be
> called/used at all - if from another thread (as I would expect) then there is a problem with
> thread-safety: FTPClient itself is not thread-safe so it means that some
> custom lock/monitor must be used; but this lock will prevent calling abort() on
> the FTPClient while it is downloading/uploading file since file upload/download
> itself is blocking...
> If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.
> Thanks a lot.
> [1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
> [2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/NET-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13098138#comment-13098138 ]

Bogdan Drozdowski commented on NET-419:
---------------------------------------

Checking if the abort command was issued could be implemented the same way as the current NOOP sending, but it has a flow (just ilke the NOOP sending) - the listener classes that are registered on the transfers are called when bytes are transferred. This means that if we wait with sending the ABOR command until some bytes are received, we're defeating the purpose of the ABOR command itself. And if we send it immediately, we have synchronization problems. If we receive data often, then the ABOR will be sent not very long after calling the abort() method. If not (including slow or already disconnected servers), the method won't do nothing. So, sure, we may try it, but this fix won't be perfect.
Maybe we could stop waiting for additional replies, so that each method that sends a command could have a synchronized block within which the command would be sent and one reply read. This way the BufferredReaders/Writers would be synchronized and other threads could send commands. This won't make the whole FTPClient thread-safe, but perhaps this would be enough for both the NOOP and ABOR to work properly during transfers. The drawback is that we're changing the behavious of some methods in an incompatible way.
I'd look for synchronized line-wise readers and writers (probably outside of the Java core classes, perhaps even somewhere in Apache) and make command sending and reply parsing synchronized methods, this could fix our problems. Finding such classes is one thing. The FTP, FTPClient, FTPSClient and maybe other classes would have to be changed. Unfortunately, currently I don't have the time to look at this closer, but I'll look into the problem later. If you have any other ideas, share them!

> Not possible to call FTPClient.abort() method correctly
> -------------------------------------------------------
>
>                 Key: NET-419
>                 URL: https://issues.apache.org/jira/browse/NET-419
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: java version "1.6.0_26"
> Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
> Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Tomas Mysik
>
> Unfortunately, it seems that there are difficulties of using FTPClient.abort()
> method [1][2]. Also, it is really not clear how the abort() method should be
> called/used at all - if from another thread (as I would expect) then there is a problem with
> thread-safety: FTPClient itself is not thread-safe so it means that some
> custom lock/monitor must be used; but this lock will prevent calling abort() on
> the FTPClient while it is downloading/uploading file since file upload/download
> itself is blocking...
> If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.
> Thanks a lot.
> [1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
> [2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/NET-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13098827#comment-13098827 ]

Tomas Mysik commented on NET-419:
---------------------------------

Thanks a lot for the analysis; frankly, I do not understand everything but if there is a solution which is not perfect but which would work in most cases, I would give it a try. But the final decision is up to you, of course.

Thanks again.


> Not possible to call FTPClient.abort() method correctly
> -------------------------------------------------------
>
>                 Key: NET-419
>                 URL: https://issues.apache.org/jira/browse/NET-419
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: java version "1.6.0_26"
> Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
> Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Tomas Mysik
>
> Unfortunately, it seems that there are difficulties of using FTPClient.abort()
> method [1][2]. Also, it is really not clear how the abort() method should be
> called/used at all - if from another thread (as I would expect) then there is a problem with
> thread-safety: FTPClient itself is not thread-safe so it means that some
> custom lock/monitor must be used; but this lock will prevent calling abort() on
> the FTPClient while it is downloading/uploading file since file upload/download
> itself is blocking...
> If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.
> Thanks a lot.
> [1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
> [2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (NET-419) Not possible to call FTPClient.abort() method correctly

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/NET-419?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bogdan Drozdowski updated NET-419:
----------------------------------

    Attachment: ftp-synchro.diff

The attached file, ftp-synchro.diff, synchronizes all the uses of the control socket (and its associated readers and writers). This should help in avoiding the incorrect replies to commands.
It also introduces a boolean that tells if the user has called abort(). Currently all it does is skipping the now-perhaps-unnecessary replies on the control channel after aborting a transfer.
This patch works for me: the FTP client does not lock because of synchronization and calling abor() on a separate Thread returns "226 Abort successful" and the file is not totally transferred. It needs a re-think, though: do we need to skip the additional answers, so the user can read them? Perhaps something else should be done?
To abort a transfer as soon as possible, abor() should be called, followed by closing the Input/OutputStream connected to the transfer. One may call interrupt() on the transfer Thread (after this, read()/write() should throw an InterruptedException, which should propagate all the way up to the code calling the FTP client), but someone noticed that it may not always work. On the other hand, closing the stream should always work.

> Not possible to call FTPClient.abort() method correctly
> -------------------------------------------------------
>
>                 Key: NET-419
>                 URL: https://issues.apache.org/jira/browse/NET-419
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: java version "1.6.0_26"
> Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
> Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
> Linux cattie 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Tomas Mysik
>         Attachments: ftp-synchro.diff
>
>
> Unfortunately, it seems that there are difficulties of using FTPClient.abort()
> method [1][2]. Also, it is really not clear how the abort() method should be
> called/used at all - if from another thread (as I would expect) then there is a problem with
> thread-safety: FTPClient itself is not thread-safe so it means that some
> custom lock/monitor must be used; but this lock will prevent calling abort() on
> the FTPClient while it is downloading/uploading file since file upload/download
> itself is blocking...
> If I'm wrong and the abort() method works then an example in Javadoc would be more than welcome.
> Thanks a lot.
> [1] http://apache-commons.680414.n4.nabble.com/Net-FTPClient-abort-problem-td739542.html
> [2] http://www.tikalk.com/java/forums/apache-ftp-client-abort-transfer

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira