Xamarin Android native HttpClient throwing exceptions though internet is available on device

Viewed 19

I have this weird error my users are facing randomly. Sometimes, when users install my app, and the app calls our API, the android http client just throws this weird exception:

\"Exception\": {
\"JniPeerMembers\": {
  \"ManagedPeerType\": \"Java.IO.IOException, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065\",
  \"JniPeerTypeName\": \"java/io/IOException\",
  \"JniPeerType\": {
    \"PeerReference\": {
      \"Handle\": {
        \"value\": 47846
      },
      \"Type\": 2,
      \"IsValid\": true
    },
    \"Name\": \"java/io/IOException\"
  },
  \"InstanceMethods\": {},
  \"InstanceFields\": {},
  \"StaticMethods\": {},
  \"StaticFields\": {}
},
\"Cause\": null,
\"Message\": \"SSL handshake aborted: ssl=0x7bb43080: I/O error during system call, Connection timed out\",
\"StackTrace\": \"  at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <745bc921f7584f8cb01262bed321f988>:0 \n  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <745bc921f7584f8cb01262bed321f988>:0 \n  at Javax.Net.Ssl.HttpsURLConnectionInvoker.Connect () [0x0000a] in <786ec849fa444dbf9954decdea4ab5fe>:0 \n  at Xamarin.Android.Net.AndroidClientHandler+<>c__DisplayClass44_0.<ConnectAsync>b__0 () [0x0007d] in <786ec849fa444dbf9954decdea4ab5fe>:0 \n  at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <6f2c2bc69dcf420aaa80e268530dc675>:0 \n  at System.Threading.Tasks.Task.Execute () [0x00000] in <6f2c2bc69dcf420aaa80e268530dc675>:0 \n--- End of stack trace from previous location where exception was thrown ---\n\n  at Xamarin.Android.Net.AndroidClientHandler.DoProcessRequest (System.Net.Http.HttpRequestMessage request, Java.Net.URL javaUrl, Java.Net.HttpURLConnection httpConnection, System.Threading.CancellationToken cancellationToken, Xamarin.Android.Net.AndroidClientHandler+RequestRedirectionState redirectState) [0x0012e] in <786ec849fa444dbf9954decdea4ab5fe>:0 \n  at Xamarin.Android.Net.AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x002d0] in <786ec849fa444dbf9954decdea4ab5fe>:0 \n  at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <39758e6683bd4e7989131d3fa8217009>:0 \n  at MobileApp.ApiServices.Implementations.Base.BaseService.Get[T] (System.String url, System.Boolean silent) [0x000eb] in <7bf4b59f082f4f889aa42a5c112cbdf5>:0 \n  at MobileApp.ApiServices.Implementations.AuthenticationService.Signin (System.String userName, System.String password) [0x000c1] in <7bf4b59f082f4f889aa42a5c112cbdf5>:0 \n  at MobileApp.ViewModels.LoginViewModel.OnEmailSigninExecute () [0x00154] in <9da9c1d9d94d42b888a64eff22f7e300>:0 \n  --- End of managed Java.IO.IOException stack trace ---\njavax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x7bb43080: I/O error during system call, Connection timed out\n\tat com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)\n\tat com.android.org.conscrypt.SslWrapper.doHandshake(SslWrapper.java:374)\n\tat com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:217)\n\tat com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)\n\tat com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)\n\tat com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)\n\tat com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)\n\tat com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)\n\tat com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)\n\tat com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)\n\tat com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)\n\tat com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)\n\tat com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)\n\tat com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)\n\tat com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(Unknown Source:0)\n\",
\"JniIdentityHashCode\": 6320254,
\"PeerReference\": {
  \"Handle\": {
    \"value\": 47610
  },
  \"Type\": 2,
  \"IsValid\": true
},
\"Handle\": {
  \"value\": 47610
},
\"Data\": {},
\"InnerException\": null,
\"Source\": \"mscorlib\",
\"HResult\": -2146233088

}

The internet connection on the Android device is active, and the API is live and accessible at the moment of the query. I don't understand why Android behaves this way. Can someone please explain ?

1 Answers

The problem caused by SSL handshake error, but I am not sure which factor caused the problem. I guess the problem isn't in the code, but in the certs/acceptable encryption algorithms for the communication channel.

Most of the problems are server sided. Chances of them being fixed by the user are low.

Please check your certs and always confirm you’ve got the support for the newest SSL and TLS versions.

Hope this can help you.

Related