dx42 / MockFtpServer

Apache License 2.0
14 stars 3 forks source link

Hangs when calling a method FTPClient::completePendingCommand #22

Closed sergei-zachesov closed 1 month ago

sergei-zachesov commented 8 months ago

I use:

During a normal connection to the server, method FTPClient::completePendingCommand works as expected. But if you use the same code for FakeFtpServer, it hangs.

If you look at the stack. Hanging in this place: FTPClient::completePendingCommand -> FTPClient::getReply(true) -> String line = controlInput.readLine();

If you call the FTPClient::getReply method anywhere, the same thing happens.

chrismair commented 8 months ago

Were there any interesting logs or stacktraces from FakeFtpServer? And which FTPClient call(s) were executed before completePendingCommand()?

It looks like the client is hanging on the controlInput.readLine(); .. i.e., the FakeFtpServer is not sending any response.

chrismair commented 8 months ago

Is it possible you have an extra call to FTPClient::completePendingCommand, or that is being called after an FTPClient method where it should not?

I am able to execute this fine, within the context of the integration tests:

    InputStream inputStream = ftpClient.retrieveFileStream(FILE1)
    ftpClient.completePendingCommand();

Now if I add an extra call to ftpClient.completePendingCommand();, then it will hang.

sergei-zachesov commented 8 months ago

Thanks for the answer! In my code, I used the inputStream.close() first, then FTPClient::completePendingCommand. It worked with real ftp. But not with a fake one. Now I swapped them and it worked with fake. I'll try to experiment again.

chrismair commented 8 months ago

Which of the FTPClient methods are you calling before that? completePendingCommand is only needed for FTPClient appendFileStream, retrieveFileStream, storeFileStream, storeUniqueFileStream (both overloaded methods), so I assume it is one of those.

BTW, this works for me as well:

    InputStream inputStream = ftpClient.retrieveFileStream(FILE1)
    inputStream.close()
    ftpClient.completePendingCommand();
sergei-zachesov commented 8 months ago

Were there any interesting logs or stacktraces from FakeFtpServer? And which FTPClient call(s) were executed before completePendingCommand()?

It looks like the client is hanging on the controlInput.readLine(); .. i.e., the FakeFtpServer is not sending any response.

Yes, that assumption was correct. Called several times or without using retrieveFileStream methods.

chrismair commented 8 months ago

I have added some integration tests using FTPClient that call retrieveFileStream(), then close the InputStream, and then calls completePendingCommand() (commit). That seems to be the required/acceptable sequence of calls. Extra calls to completePendingCommand() will definitely hang, but so far I don't think that is "wrong" or needs to be changed. See FTPClient #retrieveFileStream.

Not sure what else, if anything, to do for this issue.

chrismair commented 1 month ago

Closing. Reopen if needed.