0 votes
by (120 points)
edited by

private async void btnConnect_Clicked(object sender, EventArgs e)
 {
    try
    {
       using (var client = new Rebex.Net.Sftp())
       {
         client.LogWriter = new Rebex.TraceLogWriter();
         await client.ConnectAsync("test.rebex.net");
         client.Login("demo", "password");
       }
     }            
     catch(Exception ex)
     {
       Debug.WriteLine(ex.ToString());
     }
}

{Rebex.Net.SftpException: Socket error 10035 occured. ---> Rebex.Net.ProxySocketException: Socket error 10035 occured. ---> System.Net.Sockets.SocketException: Operation on non-blocking socket would block
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b0] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/mcs/class/System/System.Net.Sockets/Socket.cs:892 
  at knhz.Connect (System.Net.EndPoint remoteEP) [0x00101] in <72a174b311e1464398a86f420b7afa81>:0 
  at knic.ccvf (System.Net.IPEndPoint qm) [0x0015c] in <72a174b311e1464398a86f420b7afa81>:0 
  at knie.xrcj (System.Net.EndPoint eza) [0x00045] in <72a174b311e1464398a86f420b7afa81>:0 
  at Rebex.Net.ProxySocket.Connect (System.Net.EndPoint remoteEP) [0x00132] in <72a174b311e1464398a86f420b7afa81>:0 
   --- End of inner exception stack trace ---
  at Rebex.Net.ProxySocket.Connect (System.Net.EndPoint remoteEP) [0x00196] in <72a174b311e1464398a86f420b7afa81>:0 
  at Rebex.Net.ProxySocket.Connect (System.String serverName, System.Int32 serverPort) [0x0003d] in <72a174b311e1464398a86f420b7afa81>:0 
  at Rebex.Net.Sftp.dmah (System.String po, System.Int32 pp, Rebex.Net.SshParameters pq, qhhd pr) [0x001ac] in <95ea4ffd071e4c41be5d7d96f6b37bf1>:0 
   --- End of inner exception stack trace ---
  at Rebex.Net.Sftp.dmah (System.String po, System.Int32 pp, Rebex.Net.SshParameters pq, qhhd pr) [0x0031f] in <95ea4ffd071e4c41be5d7d96f6b37bf1>:0 
  at Rebex.Net.Sftp.dmcn (System.Object ww, System.Enum wx, System.Object[] wy) [0x000a9] in <95ea4ffd071e4c41be5d7d96f6b37bf1>:0 
  at bmjn.rscp (System.Object iz) [0x00008] in <e621cf0ccc5b4395bd2422fc594466d0>:0 
--- End of stack trace from previous location where exception was thrown ---

  at SFTPTest.MainPage.btnConnect_Clicked (System.Object sender, System.EventArgs e) [0x00054] in C:\Repos\SFTPTest\SFTPTest\SFTPTest\MainPage.xaml.cs:46 }

Applies to: Rebex SFTP

1 Answer

0 votes
by (150k points)

using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
    socket.Connect("test.rebex.net", 22);
}
by (120 points)
Yes, that code also fails, not as frequently, 3-4 times ok, then crash ....

With this exception :

{System.Net.Sockets.SocketException (0x80004005): Operation on non-blocking socket would block
  at System.Net.Sockets.Socket.Connect (System.Net.IPAddress[] addresses, System.Int32 port) [0x000c3] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs:1154
  at System.Net.Sockets.Socket.Connect (System.String host, System.Int32 port) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/mcs/class/System/System.Net.Sockets/Socket.cs:857
  at SFTPTest.MainPage.btnConnect_Clicked (System.Object sender, System.EventArgs e) [0x00018] in C:\Repos\SFTPTest\SFTPTest\SFTPTest\MainPage.xaml.cs:45 }
by (150k points)
Thanks! This actually looks like a bug in Xamarin or Mono. Does the code still fail if you explicitly make the Socket blocking?

    using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
    {
        socket.Blocking = true;
        socket.Connect("test.rebex.net", 22);
    }
by (120 points)
Same result, works 1-2 times, then the same Exception is thrown.
by (150k points)
Thanks for giving this a try!

Unfortunately, results of these tests indicate that the issue is not in Rebex libraries, but at a lower layer - possibly in Xamarin.Android's libraries (which are based on Mono).

Rebex libraries use .NET classes such as System.Net.Sockets.Socket, and if they don't behave properly (which is apparently the case - a blocking socket should not fail with "operation on non-blocking socket would block" error), Rebex SFTP can't work properly either.

Please ask Xamarin developers about this at Xamarin Forums (https://forums.xamarin.com/). The error comes from their code, so they should be able to investigate and help.

A bit of searching reveals that there might be some issues with sockets with Xamarin.Android on Android 10 that manifests via "Operation on non-blocking socket would block" error:, although this does directly not correspond to your scenario:
https://github.com/xamarin/xamarin-android/issues/4458
...