Skip to content

SyncTask unregisterReceiver error #6558

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

Closed
white123483 opened this issue Dec 4, 2024 · 8 comments
Closed

SyncTask unregisterReceiver error #6558

white123483 opened this issue Dec 4, 2024 · 8 comments

Comments

@white123483
Copy link

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Android Studio Koala | 2024.1.1
  • Firebase Component: Messaging
  • Component version: 24.1.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I would like to know when com.google.firebase.messaging.SyncTask will be called, because my Google Play console gets task.getContext().unregisterReceiver(this) logging out of the receiver resulting in an error message.

Relevant Code:

// TODO(you): code here to reproduce the problem
Exception java.lang.RuntimeException:
  at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0 (LoadedApk.java:1919)
  at android.app.LoadedApk$ReceiverDispatcher$Args.$r8$lambda$gDuJqgxY6Zb-ifyeubKeivTLAwk (Unknown Source)
  at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run (Unknown Source:2)
  at android.os.Handler.handleCallback (Handler.java:958)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:230)
  at android.os.Looper.loop (Looper.java:319)
  at android.app.ActivityThread.main (ActivityThread.java:8919)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
Caused by java.lang.IllegalArgumentException:
  at android.app.LoadedApk.forgetReceiverDispatcher (LoadedApk.java:1751)
  at android.app.ContextImpl.unregisterReceiver (ContextImpl.java:1933)
  at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:837)
  at com.google.firebase.messaging.SyncTask$ConnectivityChangeReceiver.onReceive (SyncTask.java:194)
  at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0 (LoadedApk.java:1911)
@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@lehcar09
Copy link
Contributor

lehcar09 commented Dec 4, 2024

Hi @white123483 , thank you for reaching out. From what I can gather, the ConnectivityChangeReceiver is a BroadcastReceiver that listens for network connectivity changes. When a connection is established, it triggers a SyncTask to perform a background synchronization. It then unregisters itself after triggering the task to avoid unnecessary resource usage.

I tried reproducing the issue, however, I did not encounter this RuntimeException. I wonder if it is caused by a race condition.

I’ll raise this to our engineers and create a PR for this issue. Thanks!

@white123483
Copy link
Author

你好@white123483,感谢您的联系。据我所知,ConnectivityChangeReceiver 是一个 BroadcastReceiver,用于监听网络连接变化。建立连接后,它会触发 SyncTask 来执行后台同步。触发任务后,它会自行注销,以避免不必要的资源使用。

我尝试重现该问题,但没有遇到此 RuntimeException。我想知道这是否是由竞争条件引起的。

我会向我们的工程师提出这个问题并针对此问题创建 PR。谢谢!

Thank you for your reply! I've tried to reproduce this issue as well, but that didn't work either, so far we only have this error in the Google Play Console crash logs, and more than two hundred users have encountered this issue. So I'm not sure of the exact possible reasons for triggering it

@Heagin-OhJeongSeok
Copy link

Heagin-OhJeongSeok commented Mar 6, 2025

This issue is also occurring in the firebase SDK for Unity (firebase-messaging-unity:12.1.0).

Could you please tell me when I can expect a fixed SDK?
#6560

This error tends to spike after each update of our game, then gradually decrease.

Firebase Crashlytics logs show that 96% of crashes occurred in the background, and 75% of crashes occurred on Android 15.

Thank you. @lehcar09

Image

@Heagin-OhJeongSeok
Copy link

I'm curious about the process for this issue.

#6560
Although the above issue was fixed for the same problem, it doesn't seem to be progressing further in the review stage.

Thank you @welishr

@welishr
Copy link
Contributor

welishr commented Mar 10, 2025

Hi, I'm not sure why a reviewer wasn't assigned for #6560 but for now we believe we should try to better ensure that we're not hitting any error case here rather than catching and ignoring the exception, that way we don't mask any possible true issue bug that may arise.

welishr added a commit that referenced this issue Mar 10, 2025
For issue #6558, this is an attempt at fixing the
IllegalArgumentException by ensuring that the context we use for
registering the SyncTask is the same context we use to unregister the
task. Race conditions dont seem like a culprit here since unregister is
only triggered by the Receiver itself, which should be only executed
synchronously on the main thread.
@Heagin-OhJeongSeok
Copy link

Heagin-OhJeongSeok commented Mar 11, 2025

Thank you for the revision. I have one more question.

We are using the Firebase Unity SDK, and I’m wondering if an issue fixed in the firebase-android-sdk repository will also be reflected in the Firebase Unity SDK? @welishr

@lehcar09
Copy link
Contributor

Hi folks! we have released the BOM version 30.11.0 that includes the fix for this. That said, I'll be closing this issue now. Let us know if there's any misunderstanding or the issue persists so we can re-open the issue. Thanks!

tejasd pushed a commit that referenced this issue Apr 1, 2025
For issue #6558, this is an attempt at fixing the
IllegalArgumentException by ensuring that the context we use for
registering the SyncTask is the same context we use to unregister the
task. Race conditions dont seem like a culprit here since unregister is
only triggered by the Receiver itself, which should be only executed
synchronously on the main thread.
@firebase firebase locked and limited conversation to collaborators Apr 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants