pult / libssh2_delphi

delphi pascal libssh2 ssh2 sftp libssh2.dll
81 stars 30 forks source link

A non-blocking socket operation could not be completed immediately #4

Closed Nico207 closed 5 years ago

Nico207 commented 6 years ago

Hi,

I encounter a problem when I send some files.

During the Put command, after some seconds, the error "A non-blocking socket operation could not be completed immediately" appears. (In french : "Une opération non bloquante sur un socket n’a pas pu être achevée immédiatement")

Error message

I performed the test on 2 SFTP servers with the same result.

Interesting thing, the problem does not occur if the file is small enough (<6MB on the first server, <40MB on the second). Other precisions :

Have you ever encountered this problem?

Nico207 commented 6 years ago

One more thing:

I just make a new test, but this time I changed the value of FTimeOut in the procedure TSSH2Client.Connect. I changed this value to 30 (default is 10). The files that were problematic are now sent, but larger files, still do not pass.

The transfert of my "huge" file takes more than 30 seconds (or 10 in the previous case) During the transfer, when everything goes well, is there an update of this timeout ?

pult commented 6 years ago

try to comment out or test various set_blocking / FTimeOut uMySFTPClient.pas // libssh2_session_set_blocking(FSession, 1); // {+} // if FTimeOut<10 then FTimeOut := 10; // {+.} // libssh2_keepalive_config(FSession, Integer(FKeepAlive), {+}{number of seconds:}FTimeOut{+.});

need test FTimeOut = 0 ...

Nico207 commented 6 years ago

Ok, here's what I tested :

  1. Comment the 5 lines you have noted above Send OK

  2. Set FTimeout to 0 Send OK

  3. Set blocking parameter of libssh2_session_set_blocking to 0 No connection (Error with message => "Could not get user auth list.")

  4. Set KeepAlive to false Send not ok -> same error as my first report

// ----------

I also noticed two strange things :

pult commented 6 years ago

1+2+3+4 : https://github.com/pult/libssh2_delphi/commit/29b3b77de88cd656130093bcb4e621a6188cf5e1

strange things TODO: need modeling ...

rburgstaler commented 5 years ago

@Nico207

strange things: upload takes 4 times longer than a "classic" client like Filezilla or WinSCP

I found the same thing and figured out that playing with WriteBufferLen would significantly change the performance. The default value of 102432-1 would take over 1:06 minutes to upload a 123 MB file where as changing it to 10241024 would take 0:10 minutes.

strange thigns: sometimes, (I couldn't find the steps to reproduce this) the size of the uploaded file doesn't correspond to its real size (a few bytes more). If I edit this file, I can see a is added at the end of all lines, in addition to the existing CRLF. For that, not sure if the problem is your function, my ftp, my computer or anything else...

I was not able to reproduce this issue. I was hoping that I could so that I could fix it before it burns me.

During the Put command, after some seconds, the error "A non-blocking socket operation could not be completed immediately" appears.

I was getting the same error as well. It turns out it was happening on uploads that took more than magic number 10 seconds to upload which happens to be the timeout setting. I found that setting KeepAlive to false makes the problem go away. (I should also note, that I was seeing this even with commit 29b3b77)

pult commented 5 years ago

I applyed your path "Fix "Invalid Pointer" error that can occur under certain circumstances" https://github.com/rburgstaler/libssh2_delphi/commit/41dfd681e3d900a22cdb4886b84fdcb38b7f7ce3

KeepAlive: Try increasing "TimeOut" property ...