Skip to content

[Production][iOS]: 2.8.1 throws Fatal Exception: NSInternalInconsistencyException Sending a message before the FlutterEngine has been run. #96901

Closed

Description

@BlakeWuh

Steps to Reproduce

  1. I haven't found a way to reproduce the crash.
  2. the crash got reported to Firebase console.

Logic of our plugin

  1. our plugin get called by - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result, start listen to some iOS native change trigger by native iOS.
  2. After the trigger, our plugin will call - (void)invokeMethod:(NSString*)method arguments:(id _Nullable)arguments to trigger some change in Flutter Dart side.
  3. 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

  1. our app is an flutter app, we never call the engine's destruct or trigger any detach.
  2. our plugin didn't change a bit.
  3. In the Flutter 2.5.3, we never come across any crash like this.
  4. 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 above
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 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!

Activity

  1. GreatZheng2023 commented on Jan 20, 2022

    @GreatZheng2023

    i have the same crash at 2.8.1

  2. BlakeWuh commented on Jan 20, 2022

    @BlakeWuh
    Author
  3. flutter-symbolizer-bot commented on Jan 20, 2022

    @flutter-symbolizer-bot
  4. BlakeWuh commented on Jan 20, 2022

    @BlakeWuh
    Author

    I found some issue alike, but not the same case? Mainly because our app won't call detach ourselves.
    #56996

  5. BlakeWuh commented on Jan 20, 2022

    @BlakeWuh
    Author

    Is it the same case described in #44256 ?

  6. BlakeWuh commented on Jan 20, 2022

    @BlakeWuh
    Author

    Is it the same case described in #44256 ?

    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????

  7. added
    in triage
    on Jan 20, 2022
  8. darshankawar commented on Jan 20, 2022

    @darshankawar
    Member

    @flutter-symbolizer-bot #96901 (comment) force flutter#v2.8.1 ios release arm64

  9. flutter-symbolizer-bot commented on Jan 20, 2022

    @flutter-symbolizer-bot

    crash from #96901 (comment) symbolized using symbols for 890a5fca2e34db413be624fc83aeea8e61d42ce6 ios-arm64-release

    #00 0000000000011404 Flutter (Missing)
    #01 000000000061206c Runner -[OurPlugin willInvokeMethod:] + 49 (OurPlugin.m:4)
    #02 0000000000614954 Runner __52-[OurPlugin somethingTriggerByIOSNative:]_block_invoke + 177 (OurPlugin.m:17)
    
    

    crash from #96901 (comment) symbolized using symbols for 890a5fca2e34db413be624fc83aeea8e61d42ce6 ios-arm64-release

    #00 00000000000982a8 Runner FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:39)
    #01 0000000000098688 Runner FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:42)
    #02 000000000008f9f8 Runner FIRCLSHandler + 34 (FIRCLSHandler.m:3)
    #03 000000000008a1a0 Runner __FIRCLSExceptionRecord_block_invoke + 218 (FIRCLSException.mm:21)
    #04 000000000000481c libdispatch.dylib _dispatch_client_callout + 20
    #05 0000000000013910 libdispatch.dylib _dispatch_lane_barrier_sync_invoke_and_complete + 60
    #06 000000000008993c Runner FIRCLSExceptionRecord + 225 (FIRCLSException.mm:22)
    #07 0000000000089c48 Runner FIRCLSExceptionRecordNSException + 111 (FIRCLSException.mm:11)
    #08 0000000000089514 Runner FIRCLSTerminateHandler() + 279 (FIRCLSException.mm:27)
    #09 0000000000012fa0 libc++abi.dylib std::__terminate(void (*)()) + 20
    #10 0000000000012f2c libc++abi.dylib std::terminate() + 48
    #11 000000000002891c libobjc.A.dylib objc_terminate + 16
    #12 0000000000004830 libdispatch.dylib _dispatch_client_callout + 40
    #13 000000000000c004 libdispatch.dylib _dispatch_lane_serial_drain + 620
    #14 000000000000cc34 libdispatch.dylib _dispatch_lane_invoke + 456
    #15 000000000000becc libdispatch.dylib _dispatch_lane_serial_drain + 308
    #16 000000000000cc00 libdispatch.dylib _dispatch_lane_invoke + 404
    #17 00000000000174bc libdispatch.dylib _dispatch_workloop_worker_thread + 764
    #18 00000000000037a4 libsystem_pthread.dylib _pthread_wqthread + 276
    #19 000000000000a74c libsystem_pthread.dylib start_wqthread + 8
    
    

    crash from #96901 (comment) symbolized using symbols for 890a5fca2e34db413be624fc83aeea8e61d42ce6 ios-arm64-release

    #00 0000000000011404 Flutter (Missing)
    #01 000000000061206c Runner -[OurPlugin willInvokeMethod:] + 49 (OurPlugin.m:4)
    #02 0000000000614954 Runner __52-[OurPlugin something triggerByNative:]_block_invoke + 177 (OurPlugin.m:17)
    
    

    crash from #96901 (comment) symbolized using symbols for 890a5fca2e34db413be624fc83aeea8e61d42ce6 ios-arm64-release

    #00 00000000000982a8 Runner FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:39)
    #01 0000000000098688 Runner FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:42)
    #02 000000000008f9f8 Runner FIRCLSHandler + 34 (FIRCLSHandler.m:3)
    #03 000000000008a1a0 Runner __FIRCLSExceptionRecord_block_invoke + 218 (FIRCLSException.mm:21)
    #04 000000000000481c libdispatch.dylib _dispatch_client_callout + 20
    #05 0000000000013910 libdispatch.dylib _dispatch_lane_barrier_sync_invoke_and_complete + 60
    #06 000000000008993c Runner FIRCLSExceptionRecord + 225 (FIRCLSException.mm:22)
    #07 0000000000089c48 Runner FIRCLSExceptionRecordNSException + 111 (FIRCLSException.mm:11)
    #08 0000000000089514 Runner FIRCLSTerminateHandler() + 279 (FIRCLSException.mm:27)
    #09 0000000000012fa0 libc++abi.dylib std::__terminate(void (*)()) + 20
    #10 0000000000012f2c libc++abi.dylib std::terminate() + 48
    #11 000000000002891c libobjc.A.dylib objc_terminate + 16
    #12 0000000000004830 libdispatch.dylib _dispatch_client_callout + 40
    #13 000000000000c004 libdispatch.dylib _dispatch_lane_serial_drain + 620
    #14 000000000000cc34 libdispatch.dylib _dispatch_lane_invoke + 456
    #15 000000000000becc libdispatch.dylib _dispatch_lane_serial_drain + 308
    #16 000000000000cc00 libdispatch.dylib _dispatch_lane_invoke + 404
    #17 00000000000174bc libdispatch.dylib _dispatch_workloop_worker_thread + 764
    #18 00000000000037a4 libsystem_pthread.dylib _pthread_wqthread + 276
    #19 000000000000a74c libsystem_pthread.dylib start_wqthread + 8
    
    
  10. darshankawar commented on Jan 20, 2022

    @darshankawar
    Member

    Labeling it for further investigation.

    /cc @gaaclarke

  11. changed the title [-]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.`[/+] on Jan 20, 2022
  12. changed the title [-][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.`[/+] on Jan 20, 2022
  13. added
    a: production
    c: crash
    on Jan 20, 2022
  14. 16 remaining items

  15. curls commented on Feb 9, 2022

    @curls

    the same crash and the same stack in 2.10.0

  16. stuartmorgan-g commented on Feb 9, 2022

    @stuartmorgan-g
    Contributor

    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.

  17. added
    r: invalid
    on Feb 10, 2022
  18. BlakeWuh commented on Feb 15, 2022

    @BlakeWuh
    Author

    I implemented - (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;clear my listeners in the new version of our app. But still the crash exists.

  19. BlakeWuh commented on Feb 15, 2022

    @BlakeWuh
    Author

    Could anyone please tell me how to not use the engine during shutdown? Can I get a notification or get a state?

  20. BlakeWuh commented on Feb 15, 2022

    @BlakeWuh
    Author

    Do I need to raise another issue to discuss this problem??

  21. stuartmorgan-g commented on Feb 15, 2022

    @stuartmorgan-g
    Contributor

    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.

    Do I need to raise another issue to discuss this problem??

    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.

  22. BlakeWuh commented on Feb 15, 2022

    @BlakeWuh
    Author

    you've been told that it's gone.

    Where will I get the notification saying that the engine was gone?

  23. stuartmorgan-g commented on Feb 15, 2022

    @stuartmorgan-g
    Contributor

    detachFromEngineForRegistrar: is called during engine shutdown, but you still need to do the appropriate coordination among your threads.

  24. BlakeWuh commented on Feb 16, 2022

    @BlakeWuh
    Author

    Understood. Thanks a lot.

  25. BlakeWuh commented on Feb 27, 2022

    @BlakeWuh
    Author

    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 the detachFromEngineForRegistrar: get called), and the crash got fixed.

  26. github-actions commented on Mar 13, 2022

    @github-actions

    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 -v and a minimal reproduction of the issue.

  27. locked as resolved and limited conversation to collaborators on Mar 13, 2022
  28. added
    package
    on Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: productionc: crashenginepackageplatform-iosr: invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions