Repository: flutter
Issue: NSInternalInconsistencyException Sending a message before the FlutterEngine has been run.
Labels: c: crash,platform-ios,engine,a: production,P2,needs repro info,team-ios,triaged-ios

The crash was received in the Firebase console. Occurs in the background.

Our app only works with push notification in the background (firebase messaging + flutter_local_notifications, push notification with action buttons).

**Actual results:** <!-- what did you see? -->


<details>
  <summary>Logs</summary>

```
Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x9a84 __exceptionPreprocess
1  libobjc.A.dylib                0x15958 objc_exception_throw
2  Foundation                     0x4bf130 _userInfoForFileAndLine
3  Flutter                        0x12bac (Missing UUID 3adbf2891ee63561a26df1652313df7e)
4  sensors_plus                   0x692c (Missing UUID 3aefceb28c3a34baba95bffdbed20516)
5  Foundation                     0x9d3c4 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
6  Foundation                     0x740fc -[NSBlockOperation main]
7  Foundation                     0x74090 __NSOPERATION_IS_INVOKING_MAIN__
8  Foundation                     0x38ef4 -[NSOperation start]
9  Foundation                     0x38c40 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__
10 Foundation                     0x3dd60 __NSOQSchedule_f
11 libdispatch.dylib              0x46738 _dispatch_block_async_invoke2
12 libdispatch.dylib              0x647c8 _dispatch_client_callout
13 libdispatch.dylib              0x3be7c _dispatch_continuation_pop$VARIANT$armv81
14 libdispatch.dylib              0x3b5b4 _dispatch_async_redirect_invoke
15 libdispatch.dylib              0x48d48 _dispatch_root_queue_drain
16 libdispatch.dylib              0x49514 _dispatch_worker_thread2
17 libsystem_pthread.dylib        0x1b14 _pthread_wqthread
18 libsystem_pthread.dylib        0x167c start_wqthread
```
```
Crashed: com.google.firebase.crashlytics.ios.exception
0  FirebaseCrashlytics            0x1eea8 FIRCLSProcessRecordAllThreads + 184
1  FirebaseCrashlytics            0x1f288 FIRCLSProcessRecordAllThreads + 1176
2  FirebaseCrashlytics            0x164d4 FIRCLSHandler + 48
3  FirebaseCrashlytics            0x111a8 __FIRCLSExceptionRecord_block_invoke + 92
4  libdispatch.dylib              0x647c8 _dispatch_client_callout + 16
5  libdispatch.dylib              0x46b54 _dispatch_lane_barrier_sync_invoke_and_complete + 52
6  FirebaseCrashlytics            0x101b4 FIRCLSExceptionRecord + 204
7  FirebaseCrashlytics            0x10cc8 FIRCLSExceptionRecordNSException + 452
8  FirebaseCrashlytics            0xfe0c FIRCLSTerminateHandler() + 404
9  Runner                         0x1ef590 CPPExceptionTerminate() + 528
10 libc++abi.dylib                0x10288 std::__terminate(void (*)()) + 16
11 libc++abi.dylib                0x10230 std::terminate() + 52
12 libobjc.A.dylib                0x2b000 objc_terminate + 12
13 libdispatch.dylib              0x647dc _dispatch_client_callout + 36
14 libdispatch.dylib              0x3be7c _dispatch_continuation_pop$VARIANT$armv81 + 436
15 libdispatch.dylib              0x3b5b4 _dispatch_async_redirect_invoke + 580
16 libdispatch.dylib              0x48d48 _dispatch_root_queue_drain + 328
17 libdispatch.dylib              0x49514 _dispatch_worker_thread2 + 160
18 libsystem_pthread.dylib        0x1b14 _pthread_wqthread + 224
19 libsystem_pthread.dylib        0x167c start_wqthread + 8
```

```
com.apple.main-thread
0  libsystem_kernel.dylib         0x19e0 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x2584 _pthread_cond_wait$VARIANT$armv81 + 1220
2  libc++.1.dylib                 0xc8b4 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 24
3  Flutter                        0x2f7768 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
4  Flutter                        0x3da0f0 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
5  Flutter                        0x14424 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
6  Flutter                        0xff90 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
7  CoreFoundation                 0x34b44 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 140
8  CoreFoundation                 0xd40d0 ___CFXRegistrationPost_block_invoke + 84
9  CoreFoundation                 0xb8b78 _CFXRegistrationPost + 404
10 CoreFoundation                 0x48308 _CFXNotificationPost + 684
11 Foundation                     0x574ec -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
12 UIKitCore                      0xc6ac48 -[UIApplication _terminateWithStatus:] + 228
13 UIKitCore                      0x270adc -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 108
14 UIKitCore                      0x64b9e8 -[_UISceneLifecycleMultiplexer forceExitWithTransitionContext:scene:] + 160
15 UIKitCore                      0xc67364 -[UIApplication workspaceShouldExit:withTransitionContext:] + 172
16 FrontBoardServices             0x3b388 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke_2 + 68
17 FrontBoardServices             0x5f70 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
18 FrontBoardServices             0x3b32c __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke + 96
19 libdispatch.dylib              0x647c8 _dispatch_client_callout + 16
20 libdispatch.dylib              0x3c408 _dispatch_block_invoke_direct$VARIANT$armv81 + 212
21 FrontBoardServices             0xf474 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
22 FrontBoardServices             0xf0b0 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 176
23 FrontBoardServices             0x11574 -[FBSSerialQueue _performNextFromRunLoopSource] + 24
24 CoreFoundation                 0xcc2b8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
25 CoreFoundation                 0xd7c18 __CFRunLoopDoSource0 + 172
26 CoreFoundation                 0x61fa8 __CFRunLoopDoSources0 + 232
27 CoreFoundation                 0x76fb0 __CFRunLoopRun + 780
28 CoreFoundation                 0x7bb7c CFRunLoopRunSpecific + 584
29 GraphicsServices               0x1984 GSEventRunModal + 160
30 UIKitCore                      0x3753c8 -[UIApplication _run] + 868
31 UIKitCore                      0x375040 UIApplicationMain + 312
32 Runner                         0x5654 main + 9 (AppDelegate.swift:9)
33 ???                            0x1a67dcdf0 (Missing)
```

```
com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1194 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x12a08 mach_msg2_internal + 76
2  libsystem_kernel.dylib         0x12c44 mach_msg_overwrite + 384
3  libsystem_kernel.dylib         0x1688 mach_msg + 20
4  CoreFoundation                 0x75fc4 __CFRunLoopServiceMachPort + 156
5  CoreFoundation                 0x77174 __CFRunLoopRun + 1232
6  CoreFoundation                 0x7bb7c CFRunLoopRunSpecific + 584
7  Foundation                     0x3e428 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
8  Foundation                     0x3e324 -[NSRunLoop(NSRunLoop) runUntilDate:] + 60
9  UIKitCore                      0x49a0e0 -[UIEventFetcher threadMain] + 424
10 Foundation                     0x55f74 __NSThread__start__ + 704
11 libsystem_pthread.dylib        0x3060 _pthread_start + 116
12 libsystem_pthread.dylib        0x1688 thread_start + 8
```

```
io.flutter.1.ui
0  libsystem_kernel.dylib         0x19b8 posix_madvise + 8
1  libsystem_kernel.dylib         0x19b8 madvise + 8
2  libsystem_malloc.dylib         0x574c mvm_madvise_free + 132
3  libsystem_malloc.dylib         0x6168 small_madvise_free_range_no_lock + 488
4  libsystem_malloc.dylib         0x70e0 free_small + 816
5  Flutter                        0x477024 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
6  Flutter                        0x47dc98 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
7  Flutter                        0x4796d4 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
8  Flutter                        0x41991c (Missing UUID 3adbf2891ee63561a26df1652313df7e)
9  Flutter                        0x418764 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
10 Flutter                        0x4d821c (Missing UUID 3adbf2891ee63561a26df1652313df7e)
11 Flutter                        0x5c7fa4 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
12 Flutter                        0x5c7d18 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
13 Flutter                        0x5c88dc (Missing UUID 3adbf2891ee63561a26df1652313df7e)
14 Flutter                        0x6aa658 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
15 Flutter                        0x573890 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
16 Flutter                        0x5732fc (Missing UUID 3adbf2891ee63561a26df1652313df7e)
17 Flutter                        0x3cc4a4 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
18 Flutter                        0x3da7a0 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
19 Flutter                        0x3dafcc (Missing UUID 3adbf2891ee63561a26df1652313df7e)
20 Flutter                        0x2f5ec4 (Missing UUID 3adbf2891ee63561a26df1652313df7e)
21 Flutter                        0x2f91fc (Missing UUID 3adbf2891ee63561a26df1652313df7e)
22 CoreFoundation                 0xc4c9c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
23 CoreFoundation                 0x84c2c __CFRunLoopDoTimer + 884
24 CoreFoundation                 0x2c450 __CFRunLoopDoTimers + 284
25 CoreFoundation                 0x77444 __CFRunLoopRun + 1952
26 CoreFoundation                 0x7bb7c CFRunLoopRunSpecific + 584
27 Flutter                        0x2f90cc (Missing UUID 3adbf2891ee63561a26df1652313df7e)
28 Flutter                        0x2f8acc (Missing UUID 3adbf2891ee63561a26df1652313df7e)
29 libsystem_pthread.dylib        0x3060 _pthread_start + 116
30 libsystem_pthread.dylib        0x1688 thread_start + 8
```

```
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.0 22A380 darwin-arm, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.74.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
```

</details>