Repository: flutter
Issue: [IOS] App Crashes with error EXC_BAD_ACCESS KERN_INVALID_ADDRESS
Labels: c: crash,platform-ios,engine,customer: crowd,a: production,P2,team-ios,triaged-ios

Hi! Unfortunately my Flutter app crashes a lot in production. I can't reproduce this issue locally, and I'm not sure if origins from my code (if so, I will provide a sample). This problem appears only on IOS. Here is the log with first few threads. I would appreciate any help as it affects a lot of users.


```
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000000d04d4

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x1048 objc_msgSend + 8
1  Flutter                        0x50d684 (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
2  Flutter                        0x419fc (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
3  Flutter                        0x3d39b8 (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
4  Flutter                        0x2fb904 (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
5  Flutter                        0x2feed0 (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
6  CoreFoundation                 0xa606c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
7  CoreFoundation                 0x303d8 __CFRunLoopDoTimer + 1016
8  CoreFoundation                 0x2b06c __CFRunLoopDoTimers + 324
9  CoreFoundation                 0xaf44 __CFRunLoopRun + 1948
10 CoreFoundation                 0x1de1c CFRunLoopRunSpecific + 572
11 GraphicsServices               0x19a0 GSEventRunModal + 160
12 UIKitCore                      0x4ec600 -[UIApplication _run] + 1080
13 UIKitCore                      0x281b08 UIApplicationMain + 2028
14 Runner                         0x6010 main + 5 (AppDelegate.swift:5)
15 ???                            0x1058c8250 (Missing)


com.apple.uikit.eventfetch-thread

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0xb10 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1134 mach_msg + 72
2  CoreFoundation                 0x6b60 __CFRunLoopServiceMachPort + 368
3  CoreFoundation                 0xac48 __CFRunLoopRun + 1184
4  CoreFoundation                 0x1de1c CFRunLoopRunSpecific + 572
5  Foundation                     0x173cc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 232
6  Foundation                     0x55c3c -[NSRunLoop(NSRunLoop) runUntilDate:] + 88
7  UIKitCore                      0x46a348 -[UIEventFetcher threadMain] + 512
8  Foundation                     0x638ac __NSThread__start__ + 792
9  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
10 libsystem_pthread.dylib        0x49fc thread_start + 8


io.flutter.1.ui

io.flutter.1.ui
0  libsystem_kernel.dylib         0xb10 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1134 mach_msg + 72
2  CoreFoundation                 0x6b60 __CFRunLoopServiceMachPort + 368
3  CoreFoundation                 0xac48 __CFRunLoopRun + 1184
4  CoreFoundation                 0x1de1c CFRunLoopRunSpecific + 572
5  Flutter                        0x2fed9c (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
6  Flutter                        0x2fe55c (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
7  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
8  libsystem_pthread.dylib        0x49fc thread_start + 8

io.flutter.1.raster

io.flutter.1.io
0  libsystem_kernel.dylib         0xb10 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1134 mach_msg + 72
2  CoreFoundation                 0x6b60 __CFRunLoopServiceMachPort + 368
3  CoreFoundation                 0xac48 __CFRunLoopRun + 1184
4  CoreFoundation                 0x1de1c CFRunLoopRunSpecific + 572
5  Flutter                        0x2fed9c (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
6  Flutter                        0x2fe55c (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
7  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
8  libsystem_pthread.dylib        0x49fc thread_start + 8

io.flutter.1.io

io.flutter.1.io
0  libsystem_kernel.dylib         0xb10 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1134 mach_msg + 72
2  CoreFoundation                 0x6b60 __CFRunLoopServiceMachPort + 368
3  CoreFoundation                 0xac48 __CFRunLoopRun + 1184
4  CoreFoundation                 0x1de1c CFRunLoopRunSpecific + 572
5  Flutter                        0x2fed9c (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
6  Flutter                        0x2fe55c (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
7  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
8  libsystem_pthread.dylib        0x49fc thread_start + 8

dart:io EventHandler

dart:io EventHandler
0  libsystem_kernel.dylib         0x22f8 kevent + 8
1  Flutter                        0x4ce794 (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
2  Flutter                        0x4fd348 (Missing UUID 5e7cb7aa584b3ca8ba93141161ceba72)
3  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
4  libsystem_pthread.dylib        0x49fc thread_start + 8

com.google.firebase.crashlytics.MachExceptionServer

com.google.firebase.crashlytics.MachExceptionServer
0  FirebaseCrashlytics            0x1f44c FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393)
1  FirebaseCrashlytics            0x1f82c FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424)
2  FirebaseCrashlytics            0x167f0 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3  FirebaseCrashlytics            0x195b8 FIRCLSMachExceptionServer + 524 (FIRCLSMachException.c:524)
4  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
5  libsystem_pthread.dylib        0x49fc thread_start + 8

JavaScriptCore bmalloc scavenger

JavaScriptCore bmalloc scavenger
0  libsystem_kernel.dylib         0x14f0 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0xcbfc _pthread_cond_wait$VARIANT$mp + 1216
2  libc++.1.dylib                 0x92b8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 24
3  JavaScriptCore                 0x1040c4c void std::__1::condition_variable_any::wait<std::__1::unique_lock<bmalloc::Mutex> >(std::__1::unique_lock<bmalloc::Mutex>&) + 108
4  JavaScriptCore                 0x1045708 bmalloc::Scavenger::threadRunLoop() + 380
5  JavaScriptCore                 0x10450bc bmalloc::Scavenger::Scavenger(std::__1::scoped_lock<bmalloc::Mutex> const&) + 10
6  JavaScriptCore                 0x104675c std::__1::__thread_specific_ptr<std::__1::__thread_struct>::set_pointer(std::__1::__thread_struct*) + 42
7  libsystem_pthread.dylib        0x63a4 _pthread_start + 116
8  libsystem_pthread.dylib        0x49fc thread_start + 8

com.google.firebase.firestore.rpc

com.google.firebase.firestore.rpc
0  libsystem_kernel.dylib         0x3dd0 poll + 8
1  grpc                           0x4c85c pollset_work(grpc_pollset*, grpc_pollset_worker**, long long) + 1024 (ev_poll_posix.cc:1024)
2  grpc                           0x4e70c pollset_work(grpc_pollset*, grpc_pollset_worker**, long long) + 324 (ev_posix.cc:324)
3  grpc                           0x409c4 cq_next(grpc_completion_queue*, gpr_timespec, void*) + 1059 (completion_queue.cc:1059)
4  grpcpp                         0xb408 grpc_impl::CompletionQueue::AsyncNextInternal(void**, bool*, gpr_timespec) + 55 (completion_queue_cc.cc:55)
5  FirebaseFirestore              0x2a2b8 firebase::firestore::remote::Datastore::PollGrpcQueue() + 141 (datastore.cc:141)
6  FirebaseFirestore              0x1169c0 firebase::firestore::util::Task::ExecuteAndRelease() + 1871 (functional:1871)
7  libdispatch.dylib              0x641a8 _dispatch_client_callout + 16
8  libdispatch.dylib              0xa0e4 _dispatch_lane_serial_drain$VARIANT$mp + 644
9  libdispatch.dylib              0xab94 _dispatch_lane_invoke$VARIANT$mp + 408
10 libdispatch.dylib              0x14760 _dispatch_workloop_worker_thread + 632
11 libsystem_pthread.dylib        0x4e84 _pthread_wqthread + 284
12 libsystem_pthread.dylib        0x49f0 start_wqthread + 8

```

Flutter Doctor:

```

✓] Flutter (Channel stable, 2.10.1, on macOS 11.5.2 20G95 darwin-x64, locale en-GB)
    • Flutter version 2.10.1 at /Users/kuba/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db747aa133 (6 days ago), 2022-02-09 13:57:35 -0600
    • Engine revision ab46186b24
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/kuba/Library/Android/sdk
    • Platform android-31, build-tools 29.0.3
    • ANDROID_HOME = /Users/kuba/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-7281165)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 12.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2
```

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Execute `flutter run` on the code sample <!-- (see "Code sample" section below) -->
2. ... <!-- describe steps to demonstrate bug -->
3. ... <!-- for example "Tap on X and see a crash" -->

**Expected results:** <!-- what did you want to see? -->

**Actual results:** <!-- what did you see? -->

<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```dart
```

</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->