Repository navigation
Closed
Labels
P2Important issues not at the top of the work lista: productionIssues experienced in live production appsc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.packageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: invalidIssue is closed as not valid
Description
Steps to Reproduce
- I haven't found a way to reproduce the crash.
- the crash got reported to Firebase console.
Logic of our plugin
- our plugin get called by
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result, start listen to some iOS native change trigger by native iOS. - After the trigger, our plugin will call
- (void)invokeMethod:(NSString*)method arguments:(id _Nullable)argumentsto trigger some change in Flutter Dart side. - iOS got crash: Fatal Exception: NSInternalInconsistencyException: Sending a message before the FlutterEngine has been run.
Why I suspect the crash has something to do with Flutter upgrade
- our app is an flutter app, we never call the engine's destruct or trigger any detach.
- our plugin didn't change a bit.
- In the Flutter 2.5.3, we never come across any crash like this.
- After we upgrade Flutter to 2.8.1, our plugin came across this crash.
Expected results:
Actual results:
Code sample
// maybe later
// the logic of our plugin is already described aboveFatal Exception: NSInternalInconsistencyException
Sending a message before the FlutterEngine has been run.
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x129754 __exceptionPreprocess
1 libobjc.A.dylib 0x287a8 objc_exception_throw
2 CoreFoundation 0x2b3f8 -[CFPrefsSearchListSource addManagedSourceForIdentifier:user:]
3 Foundation 0x7d714 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 Flutter 0x11404 (missing)
5 Runner 0x61206c -[OurPlugin willInvokeMethod:] + 49 (OurPlugin.m:49)
6 Runner 0x614954 __52-[OurPlugin somethingTriggerByIOSNative:]_block_invoke + 177 (OurPlugin.m:177)
7 libdispatch.dylib 0x2a84 _dispatch_call_block_and_release
8 libdispatch.dylib 0x481c _dispatch_client_callout
9 libdispatch.dylib 0xc004 _dispatch_lane_serial_drain
10 libdispatch.dylib 0xcc34 _dispatch_lane_invoke
11 libdispatch.dylib 0xbecc _dispatch_lane_serial_drain
12 libdispatch.dylib 0xcc00 _dispatch_lane_invoke
13 libdispatch.dylib 0x174bc _dispatch_workloop_worker_thread
14 libsystem_pthread.dylib 0x37a4 _pthread_wqthread
15 libsystem_pthread.dylib 0xa74c start_wqthread
Crashed: com.google.firebase.crashlytics.ios.exception
0 Runner 0x982a8 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393)
1 Runner 0x98688 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424)
2 Runner 0x8f9f8 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3 Runner 0x8a1a0 __FIRCLSExceptionRecord_block_invoke + 218 (FIRCLSException.mm:218)
4 libdispatch.dylib 0x481c _dispatch_client_callout + 20
5 libdispatch.dylib 0x13910 _dispatch_lane_barrier_sync_invoke_and_complete + 60
6 Runner 0x8993c FIRCLSExceptionRecord + 225 (FIRCLSException.mm:225)
7 Runner 0x89c48 FIRCLSExceptionRecordNSException + 111 (FIRCLSException.mm:111)
8 Runner 0x89514 FIRCLSTerminateHandler() + 279 (FIRCLSException.mm:279)
9 libc++abi.dylib 0x12fa0 std::__terminate(void (*)()) + 20
10 libc++abi.dylib 0x12f2c std::terminate() + 48
11 libobjc.A.dylib 0x2891c objc_terminate + 16
12 libdispatch.dylib 0x4830 _dispatch_client_callout + 40
13 libdispatch.dylib 0xc004 _dispatch_lane_serial_drain + 620
14 libdispatch.dylib 0xcc34 _dispatch_lane_invoke + 456
15 libdispatch.dylib 0xbecc _dispatch_lane_serial_drain + 308
16 libdispatch.dylib 0xcc00 _dispatch_lane_invoke + 404
17 libdispatch.dylib 0x174bc _dispatch_workloop_worker_thread + 764
18 libsystem_pthread.dylib 0x37a4 _pthread_wqthread + 276
19 libsystem_pthread.dylib 0xa74c start_wqthread + 8
Logs
Fatal Exception: NSInternalInconsistencyException
Sending a message before the FlutterEngine has been run.
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x129754 __exceptionPreprocess
1 libobjc.A.dylib 0x287a8 objc_exception_throw
2 CoreFoundation 0x2b3f8 -[CFPrefsSearchListSource addManagedSourceForIdentifier:user:]
3 Foundation 0x7d714 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 Flutter 0x11404 (missing)
5 Runner 0x61206c -[OurPlugin willInvokeMethod:] + 49 (OurPlugin.m:49)
6 Runner 0x614954 __52-[OurPlugin something triggerByNative:]_block_invoke + 177 (OurPlugin.m:177)
7 libdispatch.dylib 0x2a84 _dispatch_call_block_and_release
8 libdispatch.dylib 0x481c _dispatch_client_callout
9 libdispatch.dylib 0xc004 _dispatch_lane_serial_drain
10 libdispatch.dylib 0xcc34 _dispatch_lane_invoke
11 libdispatch.dylib 0xbecc _dispatch_lane_serial_drain
12 libdispatch.dylib 0xcc00 _dispatch_lane_invoke
13 libdispatch.dylib 0x174bc _dispatch_workloop_worker_thread
14 libsystem_pthread.dylib 0x37a4 _pthread_wqthread
15 libsystem_pthread.dylib 0xa74c start_wqthread
Crashed: com.google.firebase.crashlytics.ios.exception
0 Runner 0x982a8 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393)
1 Runner 0x98688 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424)
2 Runner 0x8f9f8 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3 Runner 0x8a1a0 __FIRCLSExceptionRecord_block_invoke + 218 (FIRCLSException.mm:218)
4 libdispatch.dylib 0x481c _dispatch_client_callout + 20
5 libdispatch.dylib 0x13910 _dispatch_lane_barrier_sync_invoke_and_complete + 60
6 Runner 0x8993c FIRCLSExceptionRecord + 225 (FIRCLSException.mm:225)
7 Runner 0x89c48 FIRCLSExceptionRecordNSException + 111 (FIRCLSException.mm:111)
8 Runner 0x89514 FIRCLSTerminateHandler() + 279 (FIRCLSException.mm:279)
9 libc++abi.dylib 0x12fa0 std::__terminate(void (*)()) + 20
10 libc++abi.dylib 0x12f2c std::terminate() + 48
11 libobjc.A.dylib 0x2891c objc_terminate + 16
12 libdispatch.dylib 0x4830 _dispatch_client_callout + 40
13 libdispatch.dylib 0xc004 _dispatch_lane_serial_drain + 620
14 libdispatch.dylib 0xcc34 _dispatch_lane_invoke + 456
15 libdispatch.dylib 0xbecc _dispatch_lane_serial_drain + 308
16 libdispatch.dylib 0xcc00 _dispatch_lane_invoke + 404
17 libdispatch.dylib 0x174bc _dispatch_workloop_worker_thread + 764
18 libsystem_pthread.dylib 0x37a4 _pthread_wqthread + 276
19 libsystem_pthread.dylib 0xa74c start_wqthread + 8
[✓] Flutter (Channel stable, 2.8.1, on macOS 11.6 20G165 darwin-arm, locale zh-Hans-CN)
• Flutter version 2.8.1 at /Users/blake/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 77d935af4d (5 weeks ago), 2021-12-16 08:37:33 -0800
• Engine revision 890a5fca2e
• Dart version 2.15.1
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/blake/Library/Android/sdk
• Platform android-32, build-tools 32.0.0
• ANDROID_HOME = /Users/blake/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• 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 11.0.10+0-b96-7249189)
[✓] VS Code (version 1.63.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.32.0
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.71
• No issues found!
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work lista: productionIssues experienced in live production appsc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.packageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: invalidIssue is closed as not valid
Activity
GreatZheng2023 commentedon Jan 20, 2022
i have the same crash at 2.8.1
BlakeWuh commentedon Jan 20, 2022
flutter-symbolizer-bot commentedon Jan 20, 2022
BlakeWuh commentedon Jan 20, 2022
I found some issue alike, but not the same case? Mainly because our app won't call detach ourselves.
#56996
BlakeWuh commentedon Jan 20, 2022
Is it the same case described in #44256 ?
BlakeWuh commentedon Jan 20, 2022
So the solution will be implementing the
- (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;?? and clear my listeners in it?If so, why is the FlutterEngine deallocating????
darshankawar commentedon Jan 20, 2022
@flutter-symbolizer-bot #96901 (comment) force flutter#v2.8.1 ios release arm64
flutter-symbolizer-bot commentedon Jan 20, 2022
crash from #96901 (comment) symbolized using symbols for
890a5fca2e34db413be624fc83aeea8e61d42ce6ios-arm64-releasecrash from #96901 (comment) symbolized using symbols for
890a5fca2e34db413be624fc83aeea8e61d42ce6ios-arm64-releasecrash from #96901 (comment) symbolized using symbols for
890a5fca2e34db413be624fc83aeea8e61d42ce6ios-arm64-releasecrash from #96901 (comment) symbolized using symbols for
890a5fca2e34db413be624fc83aeea8e61d42ce6ios-arm64-releasedarshankawar commentedon Jan 20, 2022
Labeling it for further investigation.
/cc @gaaclarke
[-]upgrade to Flutter 2.8.1, my plugin come across a new crash on iOS[/-][+][Production][iOS]: upgrade to Flutter 2.8.1 throws `Fatal Exception: NSInternalInconsistencyException Sending a message before the FlutterEngine has been run.`[/+][-][Production][iOS]: upgrade to Flutter 2.8.1 throws `Fatal Exception: NSInternalInconsistencyException Sending a message before the FlutterEngine has been run.`[/-][+][Production][iOS]: 2.8.1 throws `Fatal Exception: NSInternalInconsistencyException Sending a message before the FlutterEngine has been run.`[/+]16 remaining items
curls commentedon Feb 9, 2022
the same crash and the same stack in 2.10.0
stuartmorgan-g commentedon Feb 9, 2022
Given that all of the available evidence here is that this is a legitimate exception due to incorrectly using the engine during shutdown, I'm going to close this. If anyone experiences this crash in a scenario other than shutdown, please file a new issue with details.
BlakeWuh commentedon Feb 15, 2022
I implemented
- (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;clear my listeners in the new version of our app. But still the crash exists.BlakeWuh commentedon Feb 15, 2022
Could anyone please tell me how to not use the engine during shutdown? Can I get a notification or get a state?
BlakeWuh commentedon Feb 15, 2022
Do I need to raise another issue to discuss this problem??
stuartmorgan-g commentedon Feb 15, 2022
Clearing your listeners isn't enough if you potentially have code running on another thread already. You need to make sure that whatever code you would run to call into the engine doesn't run. That needs to happen on the thread where communication with the engine happens.
You still haven't described a Flutter issue. If you are writing multithreaded code in a plugin is your responsibility to ensure that it uses the engine correctly. That includes calling methods from the allowed thread (almost always the main thread), and not using it after you've been told that it's gone.
BlakeWuh commentedon Feb 15, 2022
Where will I get the notification saying that the engine was gone?
stuartmorgan-g commentedon Feb 15, 2022
detachFromEngineForRegistrar:is called during engine shutdown, but you still need to do the appropriate coordination among your threads.BlakeWuh commentedon Feb 16, 2022
Understood. Thanks a lot.
BlakeWuh commentedon Feb 27, 2022
The crash in our app got fixed, my solution is not only clear every listeners in my plugin(when the
detachFromEngineForRegistrar:get called), but also use a boolean value to stop everything in my plugin that called the engine (when thedetachFromEngineForRegistrar:get called), and the crash got fixed.github-actions commentedon Mar 13, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.