SFTP Exception: Socket error 10035

0 votes
asked Apr 23 by rloosme (120 points)
edited Apr 27 by Jan Sotola

In my Xamarin.Forms Android App I get an Socket Exception when Rebex.Net.Sftp.ConnectAsync(...) is called. The very first call to ConnectAsync() always works, 2 or 3 call results in the exception.

Note, this only happens on Android 10 devices. On Android 8, 9, iOS, Windows 10 UWP it works without any problems.

This is the code I'm running :

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());
     }
}

The following Exception is thrown on
await client.ConnectAsync("test.rebex.net");
:

{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 }

Any ideas what the problem might be ?

Applies to: Rebex SFTP

1 Answer

0 votes
answered Apr 23 by Lukas Pokorny (112,470 points)

This is very strange. We don't use non-blocking sockets in Rebex SFTP, so I wonder whether the error message is even correct.

Could you please try running the following code several times on Android 10 and let us know whether it fails with the same error as well?

using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
    socket.Connect("test.rebex.net", 22);
}
commented Apr 23 by rloosme (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 }
commented Apr 23 by Lukas Pokorny (112,470 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);
    }
commented Apr 27 by rloosme (120 points)
Same result, works 1-2 times, then the same Exception is thrown.
commented Apr 27 by Lukas Pokorny (112,470 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
...