quickstart-unity
quickstart-unity copied to clipboard
JniResultCallback.onCompletion Deadlocked, ANR In Firebase Unity SDK 8.9.0
[READ] For Firebase Unity SDK issues, please report to Firebase Unity open-source
Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.
[REQUIRED] Please fill in the following fields:
Unity editor version: 2020.3.22f1 Firebase Unity SDK version: 8.9.0 Source you installed the SDK: .unitypackage Problematic Firebase Component: Cloud Messaging Other Firebase Components in use: Auth, Database, Remote Config Additional SDKs you are using: Facebook, IronSource, Adjust Platform you are using the Unity editor on: Mac Platform you are targeting: Android and iOS Scripting Runtime: IL2CPP
[REQUIRED] Please describe the issue here:
Steps to reproduce:
Possible steps:
- run the app from background, maybe push
Relevant Code:
// TODO(you): code here to reproduce the problem
Hi @fdspbsteam,
Version 9.1.0 of the SDK has been released recently. Could you try it out and see if it resolves the issue? If it doesn't please provide the complete steps you've performed in order to replicate this behavior so that we can identify what's causing this.
@paulinon sorry, am I right, your suggestion is to update and check it in production?
That's right, @fdspbsteam. It's possible that the issue is resolved when an updated SDK is used.
I look forward to your results.
@paulinon honestly, we don't test potential fixes on our audience. Can you confirm that you have fixed this issue in the release?
Hi @fdspbsteam,
It's advisable that you use the latest SDK version so that you'll have the latest bug fixes and updates, and it's possible that the fix for this issue is included. Otherwise, we'll be needing more information (such as a minimal, reproducible example) to identify what's causing this.
@paulinon thanks for clarification, the stack trace in the summary of issue added, I suppose it's enough for a fix.
The stack trace you provided might be helpful for this investigation, @fdspbsteam. For now, let's see if the issue persists in the latest SDK version.
Looking forward to hearing from you soon.
@paulinon Thanks for clarification, I would like to wait until Firebase team fix this issue.
@fdspbsteam
Thank you for the info. However the information you provided is not enough for us to pinpoint the issue.
TLDR explanation is that JniResultCallback has been used by ANY C++/Unity API which wraps around Android API which returns Task
, which can be...almost any async APIs. Therefore, that can be an issue from any Firebase product (Cloud Messaging, Auth, Database, Remote Config) in your project.
I would need a bit of your help to pinpoint the issue, at least to understand which API is causing the issue.
- Are you able to reproduce the issue locally? According to this back-and-forth, I assume the answer is
No
? If you happen to be able to reproduce the issue, could you see if you can find any information from the log? - If local reproduction is not available, let's analyze the code. Could you provide code snippets int your project which is using Firebase APIs? Since the deadlock occurs in
onCompletion
, you can narrow down to something likeOnComplete()
orContinueWith()
orContinueWithOnMainThread()
, and see if you are using Firebase APIs within those blocks.
Thank you, Shawn
Ah, and, since you are using 8.9.0
, it is probably NOT related to https://github.com/firebase/quickstart-unity/issues/1151
Hey @fdspbsteam. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Hi,
Are you able to reproduce the issue locally? sorry, no
As chkuang-g mentioned above, could you provide code snippets of relevant Firebase API usage? Since the deadlock occurs in onCompletion, you can narrow down to methods like OnComplete() or ContinueWith() or ContinueWithOnMainThread(), and see if you are using Firebase APIs within those blocks.
added more info here
Hi @fdspbsteam,
While these error logs provide some context related to your issue, it would be great if you provide code snippets of relevant Firebase API usage so that this investigation can move forward.
@paulinon sure,
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
void InitializeFirebase() { DebugLog("Enabling data collection."); FirebaseAnalytics.SetAnalyticsCollectionEnabled(true); FirebaseAnalytics.SetUserId("xxxx"); FirebaseAnalytics.SetSessionTimeoutDuration(new TimeSpan(0, 30, 0)); firebaseInitialized = true; }
Thanks for the input, @fdspbsteam. Since JniResultCallback
can come from any Firebase product, could you also provide the code pertaining to Messaging, Realtime Database, Remote Config?
@paulinon we are only using Messaging part,
public static event EventHandler<MessageReceivedEventArgs> MessageReceived
FirebaseMessaging.MessageReceived += OnNotificationMessageReceived;
Hi @fdspbsteam,
Could you provide the OnNotificationMessageReceived
function in your code? We would better understand your implementation if you provide entire functions that use Firebase.
Also, does it mean that the only Firebase product you have in your implementation is Messaging?
private void OnNotificationMessageReceived(object sender, MessageReceivedEventArgs args)
{
FMLogger.vCore("Push received");
if (args != null && args.Message != null)
{
string pushId = string.IsNullOrEmpty(args.Message.MessageId) ? "null" : args.Message.MessageId;
AppState.PushNotificationId = pushId;
var data = args.Message.Data;
if (data != null)
{
foreach (var kv in data)
{
if (kv.Key == APP_MESSAGE_KEY)
{
string queue = kv.Value;
var msg = UrlSchemeParser.TryParse(queue, AppMessageSource.PushNotification);
if (msg != null)
{
NotificationAppMessageReceived?.Invoke(msg, pushId);
return;
}
}
}
}
}
else
{
Debug.LogError("empty");
}
}
**Also, does it mean that the only Firebase product you have in your implementation is Messaging?**
yep
Thanks for the additional input, @fdspbsteam. Could you also provide the function in your implementation that handles Firebase initialization?
@paulinon sure, already here https://github.com/firebase/quickstart-unity/issues/1286#issuecomment-1171550951
Thanks for the additional information, @fdspbsteam. I've relayed this to the team so that they could take a look at this issue. With that, I'll be marking this as a bug for now.
Are there any news? We still observer this issue in v9.4.0.
This issue remains in newest Unity-Firebase version 10.5.0
@paulinon can we stop the game "update to a new version" and just give the developers time to fix the issue ? )
hi @paulinon, just some information the team might want to know.
We are not able to reproduce the BUG by ourself, but according to Log, we found that our users seem to encounter this BUG few seconds after launching the game. All of them were not able to pass this line of code.
That was the only firebase call after we launch the game
Note 1. This is not call in Awake() or Start(). Note 2. 57% of this ANR happened in background. (User might be switching app to background while Initializing?)
Any update on this? we have this issue as well on production and is causing almost all of our ANRs
@gclaret hey, there is a work-around for us, maybe you wanna try. You can set Firebase.FirebaseApp.LogLevel to something other than default before check dependency.
*Note: It only reduces amount, but does not fix the problem
Hi folks,
We had a hard time reproduce this. The issue was not surfaced through our CI. And it is pretty hard to tell where this deadlock occurs in the C++/Unity SDK.
I think it is worth exploring this a bit.
- When you register for the notification, ex.
FirebaseMessaging.MessageReceived += OnNotificationMessageReceived;
, where did you do so? Is it before or duringCheckAndFixDependencyAsync.ContinueWith()
? It would be great if you can share the code snippet around this. - What are you doing during the callback? Ex. During
private void OnNotificationMessageReceived(object sender, MessageReceivedEventArgs args) {}
. Are you using any other Firebase API during this callback? Does it help if you defer the use of those APIs for the next main thread update?
This would really help us to narrow down the cause of this ANR.
Thank you, Shawn