firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.23k stars 565 forks source link

anr - with repro steps - com.google.android.c2dm.intent.RECEIVE #3382

Closed aapunain closed 2 years ago

aapunain commented 2 years ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

ANR in x.y.z PID: ## Reason: Broadcast of Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x11000010 pkg=x.y.z cmp=x.y.z/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) }

Steps to reproduce:

its getting reported in play console for app at #1

i tried to reproduce it in sample app

put Thread.sleep(15000) in Application-> onCreate()

now send message when I sent "data message" issue not reproduced but when I sent "notification message" issue reproduced

** sent message every time after killing app process

WHY IS IT SO?? .. if its because of time taken in Application's onCreate then why its not occurring for both the cases.

Relevant Code:

mentioned above
google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

argzdev commented 2 years ago

Thanks for reporting, @aapunain. May I ask which Firebase component are you using and using it at what version? Is it 29.0.3?

aapunain commented 2 years ago

Thanks for reporting, @aapunain. May I ask which Firebase component are you using and using it at what version? Is it 29.0.3?

YES implementation platform('com.google.firebase:firebase-bom:29.0.3') implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-messaging'

argzdev commented 2 years ago

Thanks for the details, @aapunain. While we look into this, any chance you could provide us an MCVE of this issue? It'll greatly help us in our investigation.

waseefakhtar commented 2 years ago

It's been the same for us. It's the # 1 ANR in our app right now. And I see there were plenty of issues opened for it but I see them closed by the bot without any solution by anyone:

https://github.com/firebase/firebase-android-sdk/issues/3308 https://github.com/firebase/firebase-android-sdk/issues/3059

Has updating to the latest BOM solved it for anyone? I currently use these versions:

"com.google.firebase:firebase-common:16.0.3"
"com.google.firebase:firebase-analytics:18.0.2"
"com.google.firebase:firebase-plugins:1.1.0"
"com.google.firebase:firebase-iid:20.0.2"
"com.google.firebase:firebase-messaging:20.2.4"
"com.google.firebase:firebase-config:19.1.1"
"com.google.firebase:firebase-crashlytics:17.2.1"
"com.google.firebase:firebase-crashlytics-gradle:2.3.0"
argzdev commented 2 years ago

Hi @waseefakhtar, ANR issues can be due to many reasons, as such we treat it as a different case for each developer. With that said, could you create a new issue with our template so we can investigate your issue as well. Thanks!

argzdev commented 2 years ago

@aapunain, could you clarify the steps to reproduce the issue, if I understand correctly:

  1. Add Thread.sleep(15000) in the onCreate method of Application class
  2. Using a server send a "notification message"
  3. App crashes after receiving message

Is this correct? Also if you could provide us an MCVE, it'll speed up our investigation, thanks!

aapunain commented 2 years ago

@argzdev yes right I will attach MCVE also by EOD

argzdev commented 2 years ago

Thanks for confirming, @aapunain. I'll wait for the MCVE. I also re-opened the issue, I think you mistakenly closed it.

aapunain commented 2 years ago

@argzdev PFA

AnrMcve.zip

argzdev commented 2 years ago

Thanks for the MCVE, @aapunain. Unfortunately, I'm unable to repro the issue.

Here is the relevant code of my node JS server:

const registrationToken = 'YOUR_REGISTRATION_TOKEN_HERE';

const message = {
  data: {
    score: '850',
    time: '2:45'
  },
  notification: {
    "body" : "This is an FCM notification that displays an image.!",
    "title" : "FCM Notification",
    "image": "https://dogtime.com/assets/uploads/2011/03/puppy-development.jpg",
  },
  token: registrationToken
};

admin.messaging().send(message)
  .then((response) => {
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

Here are the steps I did:

  1. Run the app on Android 10.0.0
  2. While app is in sleeping mode: onCreate: app sleeping
  3. Call node index.js
  4. App wakes up: onCreate: app woke up
  5. App receives message and handleintent, no crash happened.

Am I missing anything? Could you provide more details or information for me to repro the issue? Thanks!

aapunain commented 2 years ago

@argzdev don't start app first .. Kill the app process Then send the notification message.. I was sending it from 🔥base console

argzdev commented 2 years ago

Thanks for the extra details, @aapunain. I was able to repro the issue, I'll notify an engineer and see what we can do here.

fanfanxiaozu commented 2 years ago

image This timeout is too long, only leave 1s to do other things. If change it to 5000, I think anr will less.

argzdev commented 2 years ago

Thanks for the extra details, @fanfanxiaozu. It is plausible that this causes the ANR, but this may require a deeper investigation by our engineers.

Hi @aapunain, our engineers have responded with the following:

An app should avoid doing any blocking work in the main thread, including things like disk and network IO. Sleeping for seconds is a big problem. If this can be reproduced using a realistic app then it is something we can look into.

With that said, if you could provide more details about this issue, then I can probably justify an engineer’s time to dig into it with that much evidence. Thanks!

aapunain commented 2 years ago

@argzdev Thanks for details.

I agree with your point that this is happening when main thread is blocked in app's oncreate And yes this is happening in realistic app, may be that app is taking 10+ seconds in on create, I will dig that definitely.

But my point is that:

1. its happening only in case when 'notification message' is sent but not in case when 'data message' is sent, why is it so?

2. Can not this be prevented in 'notification message' case similarly?

From 'notification message' and 'data message' I mean : https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

argzdev commented 2 years ago

Hi @aapunain, unfortunately, I cannot answer your question. As of the moment, our engineers have a lot on their plates and this would require an engineer to investigate the code to check the logic with that case. If you’d like us to dig deeper on this, you could provide us with a realistic situation or an app without blocking the UI thread where this issue is experienced.

As a good practice, it is usually best not to block the main thread when performing operations, since this can cause unexpected issues. With that said, I'll be closing this issue for now, feel free to open a new ticket with the said details. Thanks!