Android/cronet + NativeAdapter = "Too many receivers, total of 1000, registered"
Package
native_dio_adapter
Version
1.3.0
Operating-System
Android
Adapter
NativeAdapter
Output of flutter doctor -v
[√] Flutter (Channel stable, 3.24.2, on Microsoft Windows [Version 10.0.22621.4037], locale en-US)
• Flutter version 3.24.2 on channel stable at C:\Flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4cf269e36d (3 weeks ago), 2024-09-03 14:30:00
• Engine revision a6bd3f1de1
• Dart version 3.5.2
• DevTools version 2.37.2
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:...\AppData\Local\Android\sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.3)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.10.35013.160
• Windows 10 SDK version 10.0.22000.0
[√] Android Studio (version 2023.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
[√] VS Code (version 1.93.1)
• VS Code at C:...\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.96.0
[√] Connected device (5 available)
• SM X910 (mobile) • 192.168.1.XXXX • android-arm64 • Android 14 (API 34)
• SM S916U1 (mobile) • 192.168.1.XXXX • android-arm64 • Android 14 (API 34)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version
10.0.22621.4037]
[√] Network resources
• All expected network resources are available.
• No issues found!
Dart Version
3.5.2
Steps to Reproduce
When using a map tiler (flutter map) with many tile layers, a limit is reached regarding "Broadcast Receivers" for Android when using NativeAdapter().
"Too many receivers, total of 1000, registered"
So I guess to reproduce, just request too many files over a network in a short period.
Expected Result
All network requests should be honored when using the NativeAdapter packge.
NOTE: if I do NOT use NativeAdapter, and just http, everything works fine for Android. However, the network requests are not as fast as with cronet, so I would rather have NativeAdapter adjusted to allow for > 1000. Or, if you could provide me with a method to "Unregister" or prevent these receivers, that would be great!
Actual Result
java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 27102, callerPackage: com.asdf.asdf
E/cr_JniAndroid(27102): at android.os.Parcel.createExceptionOrNull(Parcel.java:3077)
E/cr_JniAndroid(27102): at android.os.Parcel.createException(Parcel.java:3053)
E/cr_JniAndroid(27102): at android.os.Parcel.readException(Parcel.java:3036)
E/cr_JniAndroid(27102): at android.os.Parcel.readException(Parcel.java:2978)
E/cr_JniAndroid(27102): at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:6157)
E/cr_JniAndroid(27102): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1913)
E/cr_JniAndroid(27102): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1860)
E/cr_JniAndroid(27102): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:791)
E/cr_JniAndroid(27102): at m.ha.c(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):7)
E/cr_JniAndroid(27102): at m.ha.a(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):2)
E/cr_JniAndroid(27102): at org.chromium.net.ProxyChangeListener.start(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):56)
E/cr_JniAndroid(27102): at J.N.M6Dz0nZ5(Native Method)
E/cr_JniAndroid(27102): at m.lv.run(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):10)
E/cr_JniAndroid(27102): at android.os.Handler.handleCallback(Handler.java:958)
E/cr_JniAndroid(27102): at android.os.Handler.dispatchMessage(Handler.java:99)
E/cr_JniAndroid(27102): at android.os.Looper.loopOnce(Looper.java:230)
E/cr_JniAndroid(27102): at android.os.Looper.loop(Looper.java:319)
E/cr_JniAndroid(27102): at android.os.HandlerThread.run(HandlerThread.java:67)
E/cr_JniAndroid(27102): Caused by: android.os.RemoteException: Remote stack trace:
E/cr_JniAndroid(27102): at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:16762)
E/cr_JniAndroid(27102): at android.app.IActivityManager$Stub.onTransact$registerReceiverWithFeature$(IActivityManager.java:11613)
E/cr_JniAndroid(27102): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2961)
E/cr_JniAndroid(27102): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3199)
E/cr_JniAndroid(27102): at android.os.Binder.execTransactInternal(Binder.java:1375)
E/cr_JniAndroid(27102):
E/AndroidRuntime(27102): FATAL EXCEPTION: CronetInit
E/AndroidRuntime(27102): Process: com.asdf.asdf, PID: 27102
E/AndroidRuntime(27102): m.hg: Native stack trace:
E/AndroidRuntime(27102):
E/AndroidRuntime(27102): at org.chromium.base.JniAndroid.handleException(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):10)
E/AndroidRuntime(27102): at J.N.M6Dz0nZ5(Native Method)
E/AndroidRuntime(27102): at m.lv.run(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):10)
E/AndroidRuntime(27102): at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime(27102): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27102): at android.os.Looper.loopOnce(Looper.java:230)
E/AndroidRuntime(27102): at android.os.Looper.loop(Looper.java:319)
E/AndroidRuntime(27102): at android.os.HandlerThread.run(HandlerThread.java:67)
E/AndroidRuntime(27102): Caused by: java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 27102, callerPackage: com.asdf.asdf
E/AndroidRuntime(27102): at android.os.Parcel.createExceptionOrNull(Parcel.java:3077)
E/AndroidRuntime(27102): at android.os.Parcel.createException(Parcel.java:3053)
E/AndroidRuntime(27102): at android.os.Parcel.readException(Parcel.java:3036)
E/AndroidRuntime(27102): at android.os.Parcel.readException(Parcel.java:2978)
E/AndroidRuntime(27102): at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:6157)
E/AndroidRuntime(27102): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1913)
E/AndroidRuntime(27102): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1860)
E/AndroidRuntime(27102): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:791)
E/AndroidRuntime(27102): at m.ha.c(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):7)
E/AndroidRuntime(27102): at m.ha.a(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):2)
E/AndroidRuntime(27102): at org.chromium.net.ProxyChangeListener.start(:com.google.android.gms.dynamite_cronetdynamite@[email protected] (190400-0):56)
E/AndroidRuntime(27102): ... 7 more
E/AndroidRuntime(27102): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(27102): at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:16762)
E/AndroidRuntime(27102): at android.app.IActivityManager$Stub.onTransact$registerReceiverWithFeature$(IActivityManager.java:11613)
E/AndroidRuntime(27102): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2961)
E/AndroidRuntime(27102): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3199)
E/AndroidRuntime(27102): at android.os.Binder.execTransactInternal(Binder.java:1375)
Hi @brianquinlan. Are you familiar with related restrictions?
Im encountering the same issue here and I am not even downloading that many files (not 1000+ for sure). How exactly should we go about debugging this issue
@corepuncher: Could you disable the Android minify to produce a raw stack trace? J.N.M6Dz0nZ5(Native Method) doesn't help identify what is registering the listener.
Also, please help us by providing a minimal runnable example.
I'm not at work now so excuse me for the short reply; I think that this happens when you create a new CronetEngine (or CronetClient) per request. This is something of an anti-pattern since creating a CronetEngine is quite expensive.
I'm not at work now so excuse me for the short reply; I think that this happens when you create a new CronetEngine (or CronetClient) per request. This is something of an anti-pattern since creating a CronetEngine is quite expensive.
@brianquinlan Thanks for the insight. I'll look into related paths when available.
I'm not at work now so excuse me for the short reply; I think that this happens when you create a new CronetEngine (or CronetClient) per request. This is something of an anti-pattern since creating a CronetEngine is quite expensive.
Hello yes, this was happening because I was accidentally running a request for every build. I was using a future builder and I thought that its builder was going to execute only when a state change happens, which is stupid in hindsight. Resolved it by using a proper future initalization following the docs:
https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
@AlexV525 maybe we can display a short message that points the user to look at any excessive requests. kind of like when you use flex wrong and flutter gives you an error message explaining whats wrong
@AlexV525 maybe we can display a short message that points the user to look at any excessive requests. kind of like when you use flex wrong and flutter gives you an error message explaining whats wrong
@gokturkDev We must investigate with a proper example to understand what is going wrong. Would you be able to provide a reproducible example?
I'm not at work now so excuse me for the short reply; I think that this happens when you create a new CronetEngine (or CronetClient) per request. This is something of an anti-pattern since creating a CronetEngine is quite expensive.
From @brianquinlan 's idea, this is not the pattern that the plugin is using. The plugin only creates one engine for each adapter. https://github.com/cfug/dio/blob/main/plugins/native_dio_adapter/lib/src/native_adapter.dart
For anyone who is facing the issue, kindly provide a reproducible example for our further investigation, and we might reopen this.