Repository: flutter
Issue: mutex lock failed: Invalid argument
Labels: c: crash,platform-ios,engine,a: production,P2,team-ios,triaged-ios

We are getting the following crash reports with Firebase crash analytics on the release version of our app

```
Fatal Exception: std::__1::system_error
mutex lock failed: Invalid argument

Crashed: io.flutter.1.ui
0  FirebaseCrashlytics            0x1c9b4 FIRCLSProcessRecordAllThreads + 180
1  FirebaseCrashlytics            0x1cd94 FIRCLSProcessRecordAllThreads + 1172
2  FirebaseCrashlytics            0x15b98 FIRCLSHandler + 48
3  FirebaseCrashlytics            0x10018 __FIRCLSExceptionRecord_block_invoke + 92
4  libdispatch.dylib              0x3950 _dispatch_client_callout + 20
5  libdispatch.dylib              0x12a70 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  FirebaseCrashlytics            0xf79c FIRCLSExceptionRecord + 212
7  FirebaseCrashlytics            0xf430 FIRCLSTerminateHandler() + 588
8  libc++abi.dylib                0x12f58 std::__terminate(void (*)()) + 20
9  libc++abi.dylib                0x15efc __cxa_rethrow + 148
10 libobjc.A.dylib                0x17e8c objc_exception_rethrow + 44
11 CoreFoundation                 0x1f4b4 CFRunLoopRunSpecific + 836
12 Flutter                        0x2f0f74 (Missing)
13 Flutter                        0x2f0788 (Missing)
14 libsystem_pthread.dylib        0x1a60 _pthread_start + 148
15 libsystem_pthread.dylib        0xf5c thread_start + 8

com.apple.main-thread
0  libdyld.dylib                  0x1b76c dyld3::MachOFile::isArch(char const*) const + 72
1  libdyld.dylib                  0x1158c dyld3::Reaper::runTerminators(dyld3::LoadedImage const&) + 44
2  libdyld.dylib                  0x1158c dyld3::Reaper::runTerminators(dyld3::LoadedImage const&) + 44
3  libdyld.dylib                  0x11874 dyld3::AllImages::runAllStaticTerminators() + 168
4  libsystem_c.dylib              0x58270 __cxa_finalize_ranges + 408
5  libsystem_c.dylib              0x585c4 exit + 28
6  UIKitCore                      0xbd62f0 -[UIApplication terminateWithSuccess] + 502
7  UIKitCore                      0xbe7c98 -[UIApplication _updateStateRestorationArchiveForBackgroundEvent:saveState:exitIfCouldNotRestoreState:updateSnapshot:windowScene:] + 180
8  UIKitCore                      0xbe7564 __91-[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:]_block_invoke_2.3212 + 160
9  libdispatch.dylib              0x2a84 _dispatch_call_block_and_release + 32
10 libdispatch.dylib              0x481c _dispatch_client_callout + 20
11 libdispatch.dylib              0x12c70 _dispatch_main_queue_callback_4CF + 884
12 CoreFoundation                 0xa3340 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
13 CoreFoundation                 0x9d218 __CFRunLoopRun + 2524
14 CoreFoundation                 0x9c308 CFRunLoopRunSpecific + 600
15 GraphicsServices               0x3734 GSEventRunModal + 164
16 UIKitCore                      0xbca75c -[UIApplication _run] + 1072
17 UIKitCore                      0xbcffcc UIApplicationMain + 168
18 Runner                         0x712c main + 5 (AppDelegate.swift:5)
19 libdyld.dylib                  0x1cf8 start + 4

Thread
0  libsystem_kernel.dylib         0x2a0a4 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x37f0 _pthread_wqthread + 352
2  libsystem_pthread.dylib        0xa74c start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x2a0a4 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x37f0 _pthread_wqthread + 352
2  libsystem_pthread.dylib        0xa74c start_wqthread + 8

com.apple.mobileassetd.v2.maxpcmanager.state
0  libsystem_kernel.dylib         0x44fc mach_msg_trap + 8
1  libsystem_kernel.dylib         0x3884 mach_msg + 76
2  libdispatch.dylib              0x1e280 _dispatch_mach_send_and_wait_for_reply + 520
3  libdispatch.dylib              0x1e64c dispatch_mach_send_with_result_and_wait_for_reply + 56
4  libxpc.dylib                   0xde30 xpc_connection_send_message_with_reply_sync + 240
5  MobileAsset                    0x10664 __25-[MAXpcManager sendSync:]_block_invoke + 124
6  libdispatch.dylib              0x481c _dispatch_client_callout + 20
7  libdispatch.dylib              0x13910 _dispatch_lane_barrier_sync_invoke_and_complete + 60
8  MobileAsset                    0x105a4 -[MAXpcManager sendSync:] + 192
9  MobileAsset                    0xd990 -[MAAssetQuery queryMetaDataSync] + 708
10 DataDeliveryServices           0x11cac -[DDSMobileAssetv2Provider performAssetsForQuery:errorPtr:]
11 DataDeliveryServices           0x11a9c -[DDSMobileAssetv2Provider assetsForQuery:errorPtr:]
12 DataDeliveryServices           0x302c -[DDSAssetCenter assetsForQuery:error:]
13 LinguisticData                 0x4a28 (Missing)
14 LinguisticData                 0x3680 (Missing)
15 LinguisticData                 0x5170 LDEnumerateAssetDataItems + 304
16 ProofReader                    0x90e4 -[AppleSpell(Lexicon) enumerateAssetDataItemsForLocale:withBlock:] + 104
17 ProofReader                    0xa344 -[AppleSpell(LanguageModeling) assetDataBundleURLsForLanguage:] + 184
18 ProofReader                    0xd8b4 __37-[AppleSpell dataBundlesForLanguage:]_block_invoke.40 + 52
19 libdispatch.dylib              0x2a84 _dispatch_call_block_and_release + 32
20 libdispatch.dylib              0x481c _dispatch_client_callout + 20
21 libdispatch.dylib              0x1610c _dispatch_root_queue_drain + 688
22 libdispatch.dylib              0x167d8 _dispatch_worker_thread2 + 112
23 libsystem_pthread.dylib        0x3768 _pthread_wqthread + 216
24 libsystem_pthread.dylib        0xa74c start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0xa744 start_wqthread + 6

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x44fc mach_msg_trap + 8
1  libsystem_kernel.dylib         0x3884 mach_msg + 76
2  CoreFoundation                 0xa2e58 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0x9ccf8 __CFRunLoopRun + 1212
4  CoreFoundation                 0x9c308 CFRunLoopRunSpecific + 600
5  Foundation                     0x8d8c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 232
6  Foundation                     0x8c58 -[NSRunLoop(NSRunLoop) runUntilDate:] + 92
7  UIKitCore                      0xc7f304 -[UIEventFetcher threadMain] + 516
8  Foundation                     0x17a30c __NSThread__start__ + 864
9  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
10 libsystem_pthread.dylib        0xa758 thread_start + 8

io.flutter.1.ui
0  libsystem_kernel.dylib         0x29124 __psynch_mutexwait + 8
1  libsystem_pthread.dylib        0x71e4 _pthread_mutex_firstfit_lock_wait + 88
2  libsystem_pthread.dylib        0x7130 _pthread_mutex_firstfit_lock_slow + 232
3  libc++.1.dylib                 0x3caf4 std::__1::mutex::lock() + 16
4  Flutter                        0x2ee078 (Missing)
5  Flutter                        0x2f1098 (Missing)
6  CoreFoundation                 0xa41d4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
7  CoreFoundation                 0xa3dd0 __CFRunLoopDoTimer + 1076
8  CoreFoundation                 0xa3220 __CFRunLoopDoTimers + 328
9  CoreFoundation                 0x9cfd4 __CFRunLoopRun + 1944
10 CoreFoundation                 0x9c308 CFRunLoopRunSpecific + 600
11 Flutter                        0x2f0f74 (Missing)
12 Flutter                        0x2f0788 (Missing)
13 libsystem_pthread.dylib        0x1bfc _pthread_start + 320
14 libsystem_pthread.dylib        0xa758 thread_start + 8

io.flutter.1.io
0  libsystem_kernel.dylib         0x44fc mach_msg_trap + 8
1  libsystem_kernel.dylib         0x3884 mach_msg + 76
2  CoreFoundation                 0xa2e58 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0x9ccf8 __CFRunLoopRun + 1212
4  CoreFoundation                 0x9c308 CFRunLoopRunSpecific + 600
5  Flutter                        0x2f0f74 (Missing)
6  Flutter                        0x2f0788 (Missing)
7  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
8  libsystem_pthread.dylib        0xa758 thread_start + 8

io.worker.1
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9efc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3  Flutter                        0x2ebb60 (Missing)
4  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
5  libsystem_pthread.dylib        0xa758 thread_start + 8

io.worker.2
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9efc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3  Flutter                        0x2ebb60 (Missing)
4  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
5  libsystem_pthread.dylib        0xa758 thread_start + 8

io.worker.3
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9efc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3  Flutter                        0x2ebb60 (Missing)
4  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
5  libsystem_pthread.dylib        0xa758 thread_start + 8

io.worker.4
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9efc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3  Flutter                        0x2ebb60 (Missing)
4  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
5  libsystem_pthread.dylib        0xa758 thread_start + 8

io.worker.5
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9efc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3  Flutter                        0x2ebb60 (Missing)
4  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
5  libsystem_pthread.dylib        0xa758 thread_start + 8

io.worker.6
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9efc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3  Flutter                        0x2ebb60 (Missing)
4  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
5  libsystem_pthread.dylib        0xa758 thread_start + 8

dart:io EventHandler
0  libsystem_kernel.dylib         0x2b150 kevent + 8
1  Flutter                        0x43b48c (Missing)
2  Flutter                        0x468cc4 (Missing)
3  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
4  libsystem_pthread.dylib        0xa758 thread_start + 8

Thread
0  libsystem_pthread.dylib        0xa744 start_wqthread + 6

com.apple.root.background-qos
0  CoreFoundation                 0xc9a54 __CFStringAppendFormatCore + 14000
1  CoreFoundation                 0xca22c _CFStringCreateWithFormatAndArgumentsReturningMetadata + 164
2  Foundation                     0x8454 +[NSString stringWithFormat:] + 76
3  FBSDKCoreKit_Basics            0xe58c +[FBSDKLibAnalyzer _addClass:isClassMethod:] + 184
4  FBSDKCoreKit_Basics            0xda14 +[FBSDKLibAnalyzer getMethodsTable:frameworks:] + 284
5  FBSDKCoreKit_Basics            0xbf2c -[FBSDKCrashHandler _generateMethodMapping:] + 252
6  libdispatch.dylib              0x2a84 _dispatch_call_block_and_release + 32
7  libdispatch.dylib              0x481c _dispatch_client_callout + 20
8  libdispatch.dylib              0x1610c _dispatch_root_queue_drain + 688
9  libdispatch.dylib              0x167d8 _dispatch_worker_thread2 + 112
10 libsystem_pthread.dylib        0x3768 _pthread_wqthread + 216
11 libsystem_pthread.dylib        0xa74c start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0xa744 start_wqthread + 6

com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0x44fc mach_msg_trap + 8
1  libsystem_kernel.dylib         0x3884 mach_msg + 76
2  FirebaseCrashlytics            0x184e0 FIRCLSMachExceptionServer + 104
3  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
4  libsystem_pthread.dylib        0xa758 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x2a0a4 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x37f0 _pthread_wqthread + 352
2  libsystem_pthread.dylib        0xa74c start_wqthread + 8

DartWorker
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5460 _pthread_cond_wait + 1292
2  Flutter                        0x599374 (Missing)
3  Flutter                        0x538f18 (Missing)
4  Flutter                        0x5df254 (Missing)
5  Flutter                        0x598c9c (Missing)
6  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
7  libsystem_pthread.dylib        0xa758 thread_start + 8

DartWorker
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5460 _pthread_cond_wait + 1292
2  Flutter                        0x599374 (Missing)
3  Flutter                        0x5df214 (Missing)
4  Flutter                        0x598c9c (Missing)
5  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
6  libsystem_pthread.dylib        0xa758 thread_start + 8

DartWorker
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5460 _pthread_cond_wait + 1292
2  Flutter                        0x599374 (Missing)
3  Flutter                        0x5df214 (Missing)
4  Flutter                        0x598c9c (Missing)
5  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
6  libsystem_pthread.dylib        0xa758 thread_start + 8

com.apple.CoreMotion.MotionThread
0  libsystem_kernel.dylib         0x44fc mach_msg_trap + 8
1  libsystem_kernel.dylib         0x3884 mach_msg + 76
2  CoreFoundation                 0xa2e58 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0x9ccf8 __CFRunLoopRun + 1212
4  CoreFoundation                 0x9c308 CFRunLoopRunSpecific + 600
5  CoreFoundation                 0x9d3f4 CFRunLoopRun + 64
6  CoreMotion                     0x14cc78 CLClientCreateIso6709Notation + 196104
7  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
8  libsystem_pthread.dylib        0xa758 thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x44fc mach_msg_trap + 8
1  libsystem_kernel.dylib         0x3884 mach_msg + 76
2  CoreFoundation                 0xa2e58 __CFRunLoopServiceMachPort + 372
3  CoreFoundation                 0x9ccf8 __CFRunLoopRun + 1212
4  CoreFoundation                 0x9c308 CFRunLoopRunSpecific + 600
5  CFNetwork                      0x24bb38 _CFURLStorageSessionCopyCache + 64268
6  Foundation                     0x17a30c __NSThread__start__ + 864
7  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
8  libsystem_pthread.dylib        0xa758 thread_start + 8

JavaScriptCore bmalloc scavenger
0  libsystem_kernel.dylib         0x290cc __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x5434 _pthread_cond_wait + 1248
2  libc++.1.dylib                 0x9f98 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >) + 100
3  JavaScriptCore                 0xfd8118 bmalloc::Scavenger::threadRunLoop() + 552
4  JavaScriptCore                 0xfd7bcc bmalloc::Scavenger::Scavenger(std::__1::scoped_lock<bmalloc::Mutex> const&) + 14
5  JavaScriptCore                 0xfd90e4 std::__1::__thread_specific_ptr<std::__1::__thread_struct>::set_pointer(std::__1::__thread_struct*) + 46
6  libsystem_pthread.dylib        0x1bfc _pthread_start + 320
7  libsystem_pthread.dylib        0xa758 thread_start + 8
```

We have the following dependencies

```
dependencies:
  flutter:
    sdk: flutter
  flutter_bloc: ^7.1.0
  equatable: ^2.0.3
  firebase_auth: ^3.2.0
  firebase_core: ^1.10.0
  firebase_storage: ^10.0.2
  cloud_functions: ^3.1.1
  cloud_firestore: ^3.1.0
  firebase_messaging: ^11.1.0
  firebase_dynamic_links: ^3.0.1
  firebase_analytics: ^8.3.0
  firebase_crashlytics: ^2.2.0
  google_sign_in: ^5.0.7
  flutter_facebook_auth: ^3.5.0+1
  the_apple_sign_in: ^1.1.1
  formz: ^0.4.0
  font_awesome_flutter: ^9.1.0
  flutter_secure_storage: ^4.2.1
  permission_handler: ^8.1.4+2
  auto_size_text: ^3.0.0-nullsafety.0
  flutter_svg: ^0.22.0
  carousel_slider: ^4.0.0
  image_picker: ^0.8.3+2
  image_cropper: ^1.4.1
  device_info: ^2.0.2
  easy_localization: ^3.0.0
  google_mobile_ads: ^0.13.4
  flutter_svg_provider: ^0.1.10
  provider: ^5.0.0
  recase: ^4.0.0
  in_app_review: ^2.0.2
  sizer: ^2.0.13
  flutter_local_notifications: ^8.1.1+1
  flutter_native_timezone: ^2.0.0
  devicelocale: ^0.4.2
  shared_preferences: ^2.0.6
  visibility_detector: ^0.2.0
  in_app_purchase: ^1.0.9
  sliver_tools: ^0.2.5
  share: ^2.0.4
  path_provider: ^2.0.2
  open_file: ^3.2.1
  dio: ^4.0.0
  cached_network_image: ^3.1.0
  async: ^2.8.2
  url_launcher: ^6.0.9
  rxdart: ^0.27.1
  collection: ^1.15.0
  pausable_timer: ^1.0.0+1
  flutter_app_badger: ^1.3.0
  connectivity_plus: ^2.0.3
  new_version: ^0.2.3
```

We are using
Flutter: 2.5.3 stable channel
Dart: 2.14.4

It only happens on IOS and it happens to a large portion of our users.