Android Question ANR Crash: ANR Input dispatching timed out

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am having a issue with one of my apps when trying to connect to a product that accepts SSL connections.

I have had a number of issues with the way it connected and thought I had it fixed but keep getting ANR crash reports in my Developer Console for the app.

Erel suggested that I used the treading Library to disconnect the SSL socket connection which I did but kept getting the error coming up in my developer console.

I then thought I would use the thread Library to connect to the product and still keep getting the same error come up in my developer console.

When I run this on my Nexus 5, Nexus 7, Nexus 9 I am not getting this error come up.

The people that are reporting this issue in my developer console seem to be all Samsung devices.
I then used my old Samsung Galaxy S2 to test it out, and it seems to run fine and don't see any errors.

The ANR error I am getting in my developer console is also attached.
ANR Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 5.)

I seem to get 2 or 3 ANR reports every few weeks, so it doesn't look everyone is getting these errors, except a few people.

I was in a TeamViewer session (on the PC) with a user that had my app and the app crashed while I was in the session with them, and he said that he opened the app and it tried to connect and said when he tapped on the screen it come up with a message saying if he wanted to wait, or report the error.

When he tapped on 'report' it then submitted a ANR crash which is attached.

Based on the SSL Socket Library I am using (source code to this lib is attached) can anyone see anything wrong in this library that might be causing the error I am getting ?

I am calling a service from the Main Activity, and in that service I am calling a class and in that class I am making the SSL Socket connection.

I can't upload my B4A project since it's a released app and I don't want to publish the source code on the forum.
 

Attachments

  • SocketSSL-Source.zip
    17.8 KB · Views: 371
  • ANR.txt
    128.2 KB · Views: 880

aaronk

Well-Known Member
Licensed User
Longtime User
Thank you.. that seems to connect fine now.
Does this version still handshake the connection before it raises the Connected event ?
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Ok, thanks good to know.

I will submit my app update to Google Play and see if I get any issues from my customers about it locking up. (fingers crossed this fixed the issue)
Thanks for your help with this.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I seem to be still getting ANR crashes on this.

I have attached the latest crash.

I am using the Network library v1.51 from post 20.

On my devices I am not getting any errors etc. but am getting a few people report issues like the one attached.

Latest crash is from:
Android 5.1
Device Moto X (victara)

This time it looks like a Motorola device and not a Samsung device. The other crashes were from Samsung devices.

Any ideas on what could be causing this?

Not sure if this has anything to do with it, but I am using the Main activity to create the service and inside that service I am calling a class which is then making the connection. While the connection is being made I am loading another Activity.

Could it be that while it's connecting and I am loading another Activity have anything to do with it?
 

Attachments

  • anr.txt
    128 KB · Views: 299
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Are you checking that Successful is True?
Yes.

My Connected sub looks like this:

B4X:
Private Sub so_Connected (Successful As Boolean)
    If Successful Then
        Log("Connected")
        astream.Initialize(so.InputStream, so.OutputStream, "astream")
    End If
End Sub
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Are you sure that you are calling Socket.Connect once? Maybe there are cases where your code calls it multiple times?
I am pretty sure it's only triggering the code once but will look and check my code to confirm.

What happens if I call socket.connect while it's already connected?
Should I use Socket.close before I call socket.connect just so I know the connection is closed before trying to connect?

For Example:
B4X:
Sub ConnectToDevice
    so.Close
    so.Connect("192.168.0.123", "1234",15000)
End Sub
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
OK, Let me try that and release a update and see if that fixes the issue.
I wasn't doing it like that. I was only initialising it from the initialise sub and then connecting later on.

I will see if this code fixes the issue.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I seem to be still getting ANR crashes..

I am using a Service and in that service I am using a Class Module.

In the Class Module I am doing..

When I try and connect, I am use the following code:

B4X:
Sub Connect
    If so.IsInitialized = True Then
        so.Close
    End If


    so.InitializeSSLAcceptAll("so")
       
            Dim r As Reflector
                r.Target = so 'socket variable
                r.Target = r.GetField("socket")
                r.RunMethod4("setEnabledProtocols", Array(Array As String("TLSv1", "SSLv3")), _
                Array As String("[Ljava.lang.String;"))

so.Connect("192.168.0.35",1234,15000)
End Sub

I am then doing the following once the connection is made:

B4X:
Private Sub so_Connected (Successful As Boolean)
    If Successful Then
    astream.Initialize(so.InputStream, so.OutputStream, "astream")
    End If
End Sub

I have attached the latest ANR crash.

Any ideas what I causing this crash to keep happening?
(I am using the Network Lib from Post 20)

Latest crash come from a Galaxy Note3 (hltevzw) running Android 5.0. Looks like the same user reported it multiple times over a few days.
 

Attachments

  • ANR.txt
    128.1 KB · Views: 309
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Based on my understanding it is a bug in the OS. The handshake has already completed at that point.
Weird how it only happens sometimes and it doesn't happen on my test devices.
You would think if it was a bug it would happen all the time and it would at least happen on one of my 6 test devices.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…