Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] RuntimeException when app gets paused and returns to foreground #196

Closed
haveneersrobin opened this issue Jan 3, 2022 · 4 comments
Labels

Comments

@haveneersrobin
Copy link

Description

We see the following errors in our Sentry logging:

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.DatagramSocket.send(java.net.DatagramPacket)' on a null object reference
    at com.tradle.react.c.a(UdpSenderTask.java:3)
    at com.tradle.react.c.doInBackground(UdpSenderTask.java:1)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:353)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)

This error has occured for multiple users with different devices (all Android). The error always occurs after the activity was paused (e.g. app put to background) and the user returns to the application.

I can not share the exact code but I believe the error occurs if the user suspends the app before a response was received for a UDP broadcast message and then returns to the app.

Current behavior

An error is thrown

Expected behavior

No error is thrown, null reference is handled gracefully (?)

Relevant information

OS Android 8, 9, 10 and 11 (Nokia 5.4, Nokia 8, Samsung Galaxy A51, Samsung Galaxy S20)
react-native 0.64 and newer
react-native-udp 4.1.3 (only this version I believe)
@haveneersrobin haveneersrobin changed the title [android] RuntimeException when app gets Paused and returns to foreground [android] RuntimeException when app gets paused and returns to foreground Jan 3, 2022
@gibo77
Copy link

gibo77 commented Jan 4, 2022

How long was the App waiting for a response before the user exited the App?

@haveneersrobin
Copy link
Author

haveneersrobin commented Jan 4, 2022

Not long, the Sentry logs for the starting of the UDP broadcast and the

{
   screen: MainActivity, 
   state: paused
}

event, have the exact same timestamp... Which makes me wonder: is it possible the app is crashing?

@eliaslecomte
Copy link
Contributor

I also had a look at this and created this pr: #197.

Given that it's a nullpointer exception it looks like either:

  • A rogue AsyncTask, which is deprecated
  • The close function has been called but there are still ongoing send packets

I've added both a safeguard and replaced the AsyncTask with a better alternative.

@Rapsssito
Copy link
Collaborator

Fixed by #197.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants