-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Steps to Reproduce
I am using IsolateNameServer to handle background messages comes from firebase cloud messaging. When app receives background message from FCM, _firebaseMessagingBackgroundHandler was executed properly until sendPort.send(message). At sendPort.send app crashes without giving any visual clue or any log. The same code works as expected with Flutter 3.0.5, but does not work with any version of flutter 3.3.x.
Similar problem was reported here 2 months ago and closed as fixed. But it looks like similar problem still exists: #109248
PS: It is not easy to publish whole source code. Because it is not an open source code project and it has about 20K lines of dart code. It includes a lot of project specific codes like firebase configuration and cloud code scripts to send FCM messages.
Expected results:
Program execution should continue with Shared.debug("new firebase cloud message from port")
Actual results:
App crashes without any visual outcome or any log.
Code sample
@pragma('vm:entry-point')
static Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
try {
Shared.firebaseApp ??= await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Shared.debug("Handling a background message");
Shared.debug("background message sending to port");
final SendPort? sendPort = IsolateNameServer.lookupPortByName('firebaseCloudMessagePort');
if (sendPort == null) {
Shared.debug("sendPort is null. message not send");
} else {
Shared.debug("sending message to sendPort");
sendPort.send(message);
}
} catch (error) {
Shared.debug("Error on _firebaseMessagingBackgroundHandler: "+error.toString());
}
}
...
ReceivePort receivePort = ReceivePort();
IsolateNameServer.registerPortWithName(receivePort.sendPort, 'firebaseCloudMessagePort');
receivePort.listen((dynamic data) async {
Shared.debug("new firebase cloud message from port");
await Shared.handleFirebaseCloudMessage(data, "terminated", updateView);
if (Shared.notificationView != null) {
setView(Shared.notificationView!);
Shared.notificationView = null;
}
});
Logs
flutter run --release
Installing build/app/outputs/flutter-apk/app.apk... 34.4s
Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
D/FlutterLocationService( 3869): Creating service.
D/FlutterLocationService( 3869): Binding to location service.
I/flutter ( 3869): *** RELEASE *** Notifications.init started
W/FlutterJNI( 3869): FlutterJNI.loadLibrary called more than once
I/flutter ( 3869): *** RELEASE *** No initial message
W/FlutterJNI( 3869): FlutterJNI.prefetchDefaultFontManager called more than once
W/FlutterJNI( 3869): FlutterJNI.init called more than once
I/flutter ( 3869): *** RELEASE *** Handling a background message
I/flutter ( 3869): *** RELEASE *** background message sending to port
I/flutter ( 3869): *** RELEASE *** sending message to sendPort
flutter analyze
Analyzing armdate...
No issues found! (ran in 6.5s)
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.5, on Ubuntu 22.04.1 LTS 5.15.0-50-generic, locale en_US.UTF-8)
• Flutter version 3.3.5 on channel stable at /home/coolapps/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d9111f6402 (2 days ago), 2022-10-19 12:27:13 -0700
• Engine revision 3ad69d7be3
• Dart version 2.18.2
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /home/coolapps/development/sdk
• Platform android-33, build-tools 33.0.0
• ANDROID_HOME = /home/coolapps/development
• Java binary at: /home/coolapps/development/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 14.0.0-1ubuntu1
• cmake version 3.22.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[✓] Android Studio (version 2021.3)
• Android Studio at /home/coolapps/development/android-studio
• Flutter plugin version 70.2.3
• Dart plugin version 213.7433
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] Connected device (3 available)
• SM M526BR (mobile) • 192.168.0.29:35611 • android-arm64 • Android 12 (API 31)
• sdk gphone64 x86 64 (mobile) • emulator-5556 • android-x64 • Android 13 (API 33) (emulator)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.1 LTS 5.15.0-50-generic
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.