livekit / client-sdk-flutter

Flutter Client SDK for LiveKit
https://docs.livekit.io
Apache License 2.0
265 stars 132 forks source link

[bug] ANR from CameraCapturer.stopCapture #257

Closed furkanKotic closed 1 year ago

furkanKotic commented 1 year ago

Describe the bug Here is the ANR I see on some of my users:

main (waiting):tid=1 systid=12632 
       at java.lang.Object.wait(Object.java)
       at java.lang.Object.wait(Object.java:442)
       at java.lang.Object.wait(Object.java:568)
       at org.webrtc.CameraCapturer.stopCapture(CameraCapturer.java:23)
       at org.webrtc.Camera2Capturer.stopCapture(Camera2Capturer.java)
       at com.cloudwebrtc.webrtc.GetUserMediaImpl.removeVideoCapturer(GetUserMediaImpl.java:12)
       at com.cloudwebrtc.webrtc.MethodCallHandlerImpl.trackDispose(MethodCallHandlerImpl.java:39)
       at com.cloudwebrtc.webrtc.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:2114)
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:17)
       at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:18)
       at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:40)
       at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(DartMessenger.java)
       at io.flutter.embedding.engine.dart.DartMessenger$$InternalSyntheticLambda$1$5dd8b6f7959f08bc8717eff7469e77e06ef5aed51cc0cee17f1e13794798223f$0.run(DartMessenger.java:12)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8741)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

To Reproduce My guess is it happens when they try to turn the broadcast off.

Platform information

davidzhao commented 1 year ago

@cloudwebrtc does this mean we should move this off of the main thread for Android?

cloudwebrtc commented 1 year ago

@cloudwebrtc does this mean we should move this off of the main thread for Android?

yeah, It seems that the release operation is deadlocked in the main thread preemption, it may be caused when switching cameras

cloudwebrtc commented 1 year ago

fixed: https://github.com/flutter-webrtc/flutter-webrtc/commit/370d649f6e821df5987db7631c861ee5d99e04b6

will close when a new version is released