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

Crash: java.lang.RuntimeException: MulticastLock under-locked react-native-udp #144

Closed
hubciorz opened this issue Nov 25, 2020 · 10 comments · Fixed by #145
Closed

Crash: java.lang.RuntimeException: MulticastLock under-locked react-native-udp #144

hubciorz opened this issue Nov 25, 2020 · 10 comments · Fixed by #145
Labels

Comments

@hubciorz
Copy link

Description

App sometimes crashes after going to background (Android)

Error

com.tradle.react.UdpSockets$6.doInBackgroundGuarded
java.lang.RuntimeException: MulticastLock under-locked react-native-udp

Stack traces

android.net.wifi.WifiManager$MulticastLock.release WifiManager.java:4268
com.tradle.react.UdpSockets$6.doInBackgroundGuarded UdpSockets.java:273
com.tradle.react.UdpSockets$6.doInBackgroundGuarded UdpSockets.java:263
com.facebook.react.bridge.GuardedAsyncTask.doInBackground GuardedAsyncTask.java:36
com.facebook.react.bridge.GuardedAsyncTask.doInBackground GuardedAsyncTask.java:20
android.os.AsyncTask$3.call AsyncTask.java:378
java.util.concurrent.FutureTask.run FutureTask.java:266
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:1167
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java:641
java.lang.Thread.run Thread.java:919

Steps to reproduce

Hard to say. It happens very rarely and it seems that you need to go to background at the right moment.

Expected behavior

No crash, perhaps.

Relevant information

react-native 0.62.1
react-native-udp 4.0.3 (but happens on earlier versions, too)

Occurred on

Device OS
Xperia XZ2 Android 10.0
LG K4 Android 6.0.1
@hubciorz hubciorz added the bug label Nov 25, 2020
@Rapsssito
Copy link
Collaborator

@hubciorz, thanks for your feedback! I don't know what is causing the error, but I am working on switching all multi-thread code to the Java standard API. It might fix your issue. I will create a PR which will close this issue when merged so you are notified.

@hubciorz
Copy link
Author

@Rapsssito Good to hear that! Good luck and thank you.

@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@hubciorz
Copy link
Author

hubciorz commented Dec 1, 2020

@Rapsssito So far so good. No crashes. Tested by about 1000 users. I will let you know if there is any. Many thanks!

@hubciorz
Copy link
Author

hubciorz commented Dec 3, 2020

@Rapsssito It seems that crashes happen less frequently, but if they do, stack trace is quite different:

com.tradle.react.UdpSockets$6.run
java.lang.RuntimeException: MulticastLock under-locked react-native-udp
android.net.wifi.WifiManager$MulticastLock.release WifiManager.java:4291
com.tradle.react.UdpSockets$6.run UdpSockets.java:257
java.lang.Thread.run Thread.java:919
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:1167
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java:641
java.lang.Thread.run Thread.java:919

@Rapsssito
Copy link
Collaborator

@hubciorz could you provide me with an example code so I can reproduce the issue?

@hubciorz
Copy link
Author

hubciorz commented Dec 3, 2020

@Rapsssito This is just a standard udp listening code, as I pasted in #143 (btw, this one has been fixed). It's hard to reproduce the bug. A hint - going to background/foreground may be the key.

this.udpSocket = createSocket({ type: "udp4", reuseAddr: true })
  this.udpSocket.on("message", this.onUdp.bind(this))
  this.udpSocket.on("error", this.onUDPError.bind(this))
  this.udpSocket.on("listening", this.onUDPListening.bind(this))
  this.udpSocket.bind(7979)

  private onUDPListening(err) {
    if (err) {
      log.error("Error when listening on UDP discovering socket:", err)
      return
    }

    if (this.udpSocket) {
      log.debug("Setting multicast for socket:", this.udpSocket)
      this.udpSocket.setBroadcast(true)
      this.udpSocket.addMembership(MULTICAST_GROUP)
    } else {
      log.debug("Error when setting multicast for socket. Socket is null")
    }
  }

  private onUDPError(err) {
    log.error("Error on UDP discovering socket:", err)
  }

...
// AppState change detection logic

@hubciorz
Copy link
Author

hubciorz commented Dec 3, 2020

@Rapsssito I think it is likely to happen when someone loses wifi connection for a while. Please take a look a these comments:
andriydruk/RxDNSSD#59 (comment)
andriydruk/RxDNSSD#59 (comment)

@Rapsssito
Copy link
Collaborator

@hubciorz thanks! However, I will take care of #147 first since crashes happen more frequently. I will come back to this one once that issue is fixed.

@Rapsssito
Copy link
Collaborator

Fixed by #148

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

Successfully merging a pull request may close this issue.

2 participants