title: App crashes for iOS 11.2 CFRunLoopServiceMachPort
body: <p>I have a few CFRunLoopServiceMachPort crashes for my app. I've been trying to figure out the root cause for this. </p>
  
  <p>There is some task that I am doing in background thread to avoid congestion on Main thread. I guess this might have some part in this.</p>
  
  <p>To be honest, I couldn't understand where is my problem.</p>
  
  <p>Following is my crash log:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>CrashReporter Key:   b221bb6de8d8fdef7ea28e06270c15e1f055a7c7
  Hardware Model:      iPhone10,6
  Process:             MyApp [447]
  Path:                /private/var/containers/Bundle/Application/A3EE5740-4D42-4A91-A193-0C0212092D5F/MyApp.app/MyApp
  Identifier:          com.MyApp.MyAppphotos
  Version:             1 (2.0.3)
  Code Type:           ARM-64 (Native)
  Role:                Foreground
  Parent Process:      launchd [1]
  Coalition:           com.MyApp.MyAppphotos [545]
  
  
  Date/Time:           2018-01-11 16:25:27.9335 -0300
  Launch Time:         2018-01-11 16:24:22.4630 -0300
  OS Version:          iPhone OS 11.2.5 (15D5057a)
  Baseband Version:    1.03.06
  Report Version:      104
  
  Exception Type:  EXC_CRASH (SIGSEGV)
  Exception Codes: 0x0000000000000000, 0x0000000000000000
  Exception Note:  EXC_CORPSE_NOTIFY
  Termination Signal: Segmentation fault: 11
  Termination Reason: Namespace SIGNAL, Code 0xb
  Terminating Process: MyApp [447]
  Triggered by Thread:  0
  
  Thread 0 name:
  Thread 0 Crashed:
  0   libsystem_kernel.dylib         0x000000018257f568 mach_msg_trap + 8
  1   libsystem_kernel.dylib         0x000000018257f3e0 mach_msg + 72 (mach_msg.c:103)
  2   CoreFoundation                 0x0000000182a33108 __CFRunLoopServiceMachPort + 196 (CFRunLoop.c:2613)
  3   CoreFoundation                 0x0000000182a30cd4 __CFRunLoopRun + 1424 (CFRunLoop.c:2969)
  4   CoreFoundation                 0x0000000182950c58 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3245)
  5   GraphicsServices               0x00000001847faf84 GSEventRunModal + 100 (GSEvent.c:2245)
  6   UIKit                          0x000000018c0a6804 UIApplicationMain + 236 (UIApplication.m:3956)
  7   MyApp                      0x000000010095e0cc main + 172 (main.m:16)
  8   libdyld.dylib                  0x000000018247056c start + 4
  
  Thread 1 name:
  Thread 1:
  0   libsystem_kernel.dylib         0x00000001825a17c4 kevent_id + 8
  1   libdispatch.dylib              0x0000000182454e4c _dispatch_kq_poll + 208 (event_kevent.c:644)
  2   libdispatch.dylib              0x000000018245583c _dispatch_event_loop_wait_for_ownership$VARIANT$armv81 + 432 (event_kevent.c:2009)
  3   libdispatch.dylib              0x000000018244d098 _dispatch_sync_wait + 420 (queue.c:4197)
  4   CoreData                       0x00000001852ecb4c -[NSManagedObjectContext performBlockAndWait:] + 304 (NSManagedObjectContext.m:3714)
  5   PhotoLibraryServices           0x00000001904da010 -[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:] + 368 (PLPhotoLibrary+MegaMocAdditions.m:581)
  6   PhotoLibraryServices           0x00000001904d9a24 -[PLPhotoLibrary(MegaMocAdditions) performBlockAndWait:] + 80 (PLPhotoLibrary+MegaMocAdditions.m:314)
  7   Photos                         0x0000000191208da0 +[PHAsset originalUniformTypeIdentifierForAsset:] + 196 (PHAsset.m:2605)
  8   Photos                         0x000000019116d760 -[PHInternalAssetResource _populateFromAsset:] + 176 (PHInternalAssetResource.m:84)
  9   Photos                         0x000000019116e714 -[PHInternalAssetResource initWithResourceType:fromAsset:managedAsset:] + 644 (PHInternalAssetResource.m:271)
  10  Photos                         0x000000019116ef90 +[PHInternalAssetResource resourceForType:fromAsset:managedAsset:] + 104 (PHInternalAssetResource.m:359)
  11  Photos                         0x00000001911633a8 __61+[PHAssetResource assetResourcesForAsset:includeDerivatives:]_block_invoke_3 + 48 (PHAssetResource.m:98)
  12  Photos                         0x000000019118ebe8 PHEnumerateAssetResourceTypes + 44 (PHAssetResourceUtilities.m:100)
  13  Photos                         0x0000000191163294 __61+[PHAssetResource assetResourcesForAsset:includeDerivatives:]_block_invoke + 640 (PHAssetResource.m:97)
  14  PhotoLibraryServices           0x00000001904da110 __131-[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:]_block_invoke + 128 (PLPhotoLibrary+MegaMocAdditions.m:476)
  15  CoreData                       0x00000001852ecc48 developerSubmittedBlockToNSManagedObjectContextPerform + 156 (NSManagedObjectContext.m:3593)
  16  libdispatch.dylib              0x000000018240aa14 _dispatch_client_callout + 16 (object.m:502)
  17  libdispatch.dylib              0x000000018244d5ec _dispatch_sync_invoke_and_complete_recurse + 64 (queue.c:3689)
  18  libdispatch.dylib              0x000000018244d0f8 _dispatch_sync_wait + 516 (queue.c:4208)
  19  CoreData                       0x00000001852ecb4c -[NSManagedObjectContext performBlockAndWait:] + 304 (NSManagedObjectContext.m:3714)
  20  PhotoLibraryServices           0x00000001904da010 -[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:] + 368 (PLPhotoLibrary+MegaMocAdditions.m:581)
  21  PhotoLibraryServices           0x00000001904d9a24 -[PLPhotoLibrary(MegaMocAdditions) performBlockAndWait:] + 80 (PLPhotoLibrary+MegaMocAdditions.m:314)
  22  Photos                         0x0000000191162fb4 +[PHAssetResource assetResourcesForAsset:includeDerivatives:] + 276 (PHAssetResource.m:75)
  23  MyApp                      0x000000010093ca58 -[SharedData updateMediaObjectsToVideoFromLivePhotos:] + 808 (SharedData.m:342)
  24  MyApp                      0x000000010093be30 __30-[SharedData albumsPopulated:]_block_invoke_2 + 60 (SharedData.m:265)
  25  libdispatch.dylib              0x000000018240aa54 _dispatch_call_block_and_release + 24 (init.c:994)
  26  libdispatch.dylib              0x000000018240aa14 _dispatch_client_callout + 16 (object.m:502)
  27  libdispatch.dylib              0x0000000182446394 _dispatch_queue_override_invoke$VARIANT$armv81 + 700 (inline_internal.h:2500)
  28  libdispatch.dylib              0x000000018244c2a4 _dispatch_root_queue_drain + 568 (inline_internal.h:2539)
  29  libdispatch.dylib              0x000000018244c008 _dispatch_worker_thread3 + 112 (queue.c:6104)
  30  libsystem_pthread.dylib        0x00000001826b306c _pthread_wqthread + 1268 (pthread.c:2286)
  31  libsystem_pthread.dylib        0x00000001826b2b6c start_wqthread + 4
  
  Thread 2 name:
  Thread 2:
  0   libsystem_kernel.dylib         0x000000018257f568 mach_msg_trap + 8
  1   libsystem_kernel.dylib         0x000000018257f3e0 mach_msg + 72 (mach_msg.c:103)
  2   CoreFoundation                 0x0000000182a33108 __CFRunLoopServiceMachPort + 196 (CFRunLoop.c:2613)
  3   CoreFoundation                 0x0000000182a30cd4 __CFRunLoopRun + 1424 (CFRunLoop.c:2969)
  4   CoreFoundation                 0x0000000182950c58 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3245)
  5   Foundation                     0x0000000183385594 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304 (NSRunLoop.m:367)
  6   Foundation                     0x00000001833a49ac -[NSRunLoop(NSRunLoop) runUntilDate:] + 96 (NSRunLoop.m:411)
  7   UIKit                          0x000000018cc107d8 -[UIEventFetcher threadMain] + 136 (UIEventFetcher.m:437)
  8   Foundation                     0x00000001834870f4 __NSThread__start__ + 996 (NSThread.m:1181)
  9   libsystem_pthread.dylib        0x00000001826b42b4 _pthread_body + 308 (pthread.c:740)
  10  libsystem_pthread.dylib        0x00000001826b4180 _pthread_start + 312 (pthread.c:799)
  11  libsystem_pthread.dylib        0x00000001826b2b74 thread_start + 4
  
  Thread 3 name:
  Thread 3:
  0   libsystem_kernel.dylib         0x00000001825a17c4 kevent_id + 8
  1   libdispatch.dylib              0x0000000182454e4c _dispatch_kq_poll + 208 (event_kevent.c:644)
  2   libdispatch.dylib              0x000000018245583c _dispatch_event_loop_wait_for_ownership$VARIANT$armv81 + 432 (event_kevent.c:2009)
  3   libdispatch.dylib              0x000000018244d098 _dispatch_sync_wait + 420 (queue.c:4197)
  4   CoreData                       0x00000001852ecb4c -[NSManagedObjectContext performBlockAndWait:] + 304 (NSManagedObjectContext.m:3714)
  5   PhotoLibraryServices           0x00000001904da010 -[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:] + 368 (PLPhotoLibrary+MegaMocAdditions.m:581)
  6   PhotoLibraryServices           0x00000001904d9a24 -[PLPhotoLibrary(MegaMocAdditions) performBlockAndWait:] + 80 (PLPhotoLibrary+MegaMocAdditions.m:314)
  7   Photos                         0x0000000191162fb4 +[PHAssetResource assetResourcesForAsset:includeDerivatives:] + 276 (PHAssetResource.m:75)
  8   MyApp                      0x000000010093ca58 -[SharedData updateMediaObjectsToVideoFromLivePhotos:] + 808 (SharedData.m:342)
  9   MyApp                      0x000000010093be30 __30-[SharedData albumsPopulated:]_block_invoke_2 + 60 (SharedData.m:265)
  10  libdispatch.dylib              0x000000018240aa54 _dispatch_call_block_and_release + 24 (init.c:994)
  11  libdispatch.dylib              0x000000018240aa14 _dispatch_client_callout + 16 (object.m:502)
  12  libdispatch.dylib              0x0000000182446394 _dispatch_queue_override_invoke$VARIANT$armv81 + 700 (inline_internal.h:2500)
  13  libdispatch.dylib              0x000000018244c2a4 _dispatch_root_queue_drain + 568 (inline_internal.h:2539)
  14  libdispatch.dylib              0x000000018244c008 _dispatch_worker_thread3 + 112 (queue.c:6104)
  15  libsystem_pthread.dylib        0x00000001826b306c _pthread_wqthread + 1268 (pthread.c:2286)
  16  libsystem_pthread.dylib        0x00000001826b2b6c start_wqthread + 4
  
  Thread 4 name:
  Thread 4:
  0   libsystem_kernel.dylib         0x00000001825a17c4 kevent_id + 8
  1   libdispatch.dylib              0x0000000182454e4c _dispatch_kq_poll + 208 (event_kevent.c:644)
  2   libdispatch.dylib              0x000000018245583c _dispatch_event_loop_wait_for_ownership$VARIANT$armv81 + 432 (event_kevent.c:2009)
  3   libdispatch.dylib              0x000000018244d098 _dispatch_sync_wait + 420 (queue.c:4197)
  4   CoreData                       0x00000001852ecb4c -[NSManagedObjectContext performBlockAndWait:] + 304 (NSManagedObjectContext.m:3714)
  5   PhotoLibraryServices           0x00000001904da010 -[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:] + 368 (PLPhotoLibrary+MegaMocAdditions.m:581)
  6   PhotoLibraryServices           0x00000001904d9a24 -[PLPhotoLibrary(MegaMocAdditions) performBlockAndWait:] + 80 (PLPhotoLibrary+MegaMocAdditions.m:314)
  7   Photos                         0x0000000191162fb4 +[PHAssetResource assetResourcesForAsset:includeDerivatives:] + 276 (PHAssetResource.m:75)
  8   MyApp                      0x000000010093ca58 -[SharedData updateMediaObjectsToVideoFromLivePhotos:] + 808 (SharedData.m:342)
  9   MyApp                      0x000000010093be30 __30-[SharedData albumsPopulated:]_block_invoke_2 + 60 (SharedData.m:265)
  10  libdispatch.dylib              0x000000018240aa54 _dispatch_call_block_and_release + 24 (init.c:994)
  11  libdispatch.dylib              0x000000018240aa14 _dispatch_client_callout + 16 (object.m:502)
  12  libdispatch.dylib              0x0000000182446394 _dispatch_queue_override_invoke$VARIANT$armv81 + 700 (inline_internal.h:2500)
  13  libdispatch.dylib              0x000000018244c2a4 _dispatch_root_queue_drain + 568 (inline_internal.h:2539)
  14  libdispatch.dylib              0x000000018244c008 _dispatch_worker_thread3 + 112 (queue.c:6104)
  15  libsystem_pthread.dylib        0x00000001826b306c _pthread_wqthread + 1268 (pthread.c:2286)
  16  libsystem_pthread.dylib        0x00000001826b2b6c start_wqthread + 4
  
  Thread 5 name:
  Thread 5:
  0   libsystem_kernel.dylib         0x00000001825a17c4 kevent_id + 8
  1   libdispatch.dylib              0x0000000182454e4c _dispatch_kq_poll + 208 (event_kevent.c:644)
  2   libdispatch.dylib              0x000000018245583c _dispatch_event_loop_wait_for_ownership$VARIANT$armv81 + 432 (event_kevent.c:2009)
  3   libdispatch.dylib              0x000000018244d098 _dispatch_sync_wait + 420 (queue.c:4197)
  4   CoreData                       0x00000001852ecb4c -[NSManagedObjectContext performBlockAndWait:] + 304 (NSManagedObjectContext.m:3714)
  5   PhotoLibraryServices           0x00000001904da010 -[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:] + 368 (PLPhotoLibrary+MegaMocAdditions.m:581)
  6   PhotoLibraryServices           0x00000001904d9a24 -[PLPhotoLibrary(MegaMocAdditions) performBlockAndWait:] + 80 (PLPhotoLibrary+MegaMocAdditions.m:314)
  7   Photos                         0x0000000191162fb4 +[PHAssetResource assetResourcesForAsset:includeDerivatives:] + 276 (PHAssetResource.m:75)
  8   MyApp                      0x000000010093ca58 -[SharedData updateMediaObjectsToVideoFromLivePhotos:] + 808 (SharedData.m:342)
  9   MyApp                      0x000000010093be30 __30-[SharedData albumsPopulated:]_block_invoke_2 + 60 (SharedData.m:265)
  10  libdispatch.dylib              0x000000018240aa54 _dispatch_call_block_and_release + 24 (init.c:994)
  11  libdispatch.dylib              0x000000018240aa14 _dispatch_client_callout + 16 (object.m:502)
  12  libdispatch.dylib              0x0000000182446394 _dispatch_queue_override_invoke$VARIANT$armv81 + 700 (inline_internal.h:2500)
  13  libdispatch.dylib              0x000000018244c2a4 _dispatch_root_queue_drain + 568 (inline_internal.h:2539)
  14  libdispatch.dylib              0x000000018244c008 _dispatch_worker_thread3 + 112 (queue.c:6104)
  15  libsystem_pthread.dylib        0x00000001826b306c _pthread_wqthread + 1268 (pthread.c:2286)
  16  libsystem_pthread.dylib        0x00000001826b2b6c start_wqthread + 4
  
  Thread 6 name:
  Thread 6:
  0   libsystem_kernel.dylib         0x000000018257f568 mach_msg_trap + 8
  1   libsystem_kernel.dylib         0x000000018257f3e0 mach_msg + 72 (mach_msg.c:103)
  2   CoreFoundation                 0x0000000182a33108 __CFRunLoopServiceMachPort + 196 (CFRunLoop.c:2613)
  3   CoreFoundation                 0x0000000182a30cd4 __CFRunLoopRun + 1424 (CFRunLoop.c:2969)
  4   CoreFoundation                 0x0000000182950c58 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3245)
  5   CoreFoundation                 0x000000018299fd54 CFRunLoopRun + 116 (CFRunLoop.c:3269)
  6   CoreMotion                     0x0000000187dbf0e8 CLMotionCore::runMotionThread(void*) + 952 (CLMotionCore.mm:316)
  7   libsystem_pthread.dylib        0x00000001826b42b4 _pthread_body + 308 (pthread.c:740)
  8   libsystem_pthread.dylib        0x00000001826b4180 _pthread_start + 312 (pthread.c:799)
  9   libsystem_pthread.dylib        0x00000001826b2b74 thread_start + 4
  
  Thread 7 name:
  Thread 7:
  0   libsystem_kernel.dylib         0x000000018257f568 mach_msg_trap + 8
  1   libsystem_kernel.dylib         0x000000018257f3e0 mach_msg + 72 (mach_msg.c:103)
  2   MyApp                      0x0000000100f6e2ec CLSMachExceptionServer + 100
  3   libsystem_pthread.dylib        0x00000001826b42b4 _pthread_body + 308 (pthread.c:740)
  4   libsystem_pthread.dylib        0x00000001826b4180 _pthread_start + 312 (pthread.c:799)
  5   libsystem_pthread.dylib        0x00000001826b2b74 thread_start + 4
  
  Thread 8 name:
  Thread 8:
  0   libsystem_kernel.dylib         0x00000001825a17c4 kevent_id + 8
  1   libdispatch.dylib              0x0000000182454e4c _dispatch_kq_poll + 208 (event_kevent.c:644)
  2   libdispatch.dylib              0x000000018245583c _dispatch_event_loop_wait_for_ownership$VARIANT$armv81 + 432 (event_kevent.c:2009)
  3   libdispatch.dylib              0x000000018244d098 _dispatch_sync_wait + 420 (queue.c:4197)
  4   CoreData                       0x00000001852ecb4c -[NSManagedObjectContext performBlockAndWait:] + 304 (NSManagedObjectContext.m:3714)
  5   PhotoLibraryServices           0x00000001904da010 -[PLPhotoLibrary(MegaMocAdditions) _withDispatchGroup:synchronously:priority:name:shouldSave:performTransaction:completionHandler:] + 368 (PLPhotoLibrary+MegaMocAdditions.m:581)
  6   PhotoLibraryServices           0x00000001904d9a24 -[PLPhotoLibrary(MegaMocAdditions) performBlockAndWait:] + 80 (PLPhotoLibrary+MegaMocAdditions.m:314)
  7   Photos                         0x0000000191162fb4 +[PHAssetResource assetResourcesForAsset:includeDerivatives:] + 276 (PHAssetResource.m:75)
  8   MyApp                      0x000000010093ca58 -[SharedData updateMediaObjectsToVideoFromLivePhotos:] + 808 (SharedData.m:342)
  9   MyApp                      0x000000010093be30 __30-[SharedData albumsPopulated:]_block_invoke_2 + 60 (SharedData.m:265)
  10  libdispatch.dylib              0x000000018240aa54 _dispatch_call_block_and_release + 24 (init.c:994)
  11  libdispatch.dylib              0x000000018240aa14 _dispatch_client_callout + 16 (object.m:502)
  12  libdispatch.dylib              0x0000000182446394 _dispatch_queue_override_invoke$VARIANT$armv81 + 700 (inline_internal.h:2500)
  13  libdispatch.dylib              0x000000018244c2a4 _dispatch_root_queue_drain + 568 (inline_internal.h:2539)
  14  libdispatch.dylib              0x000000018244c008 _dispatch_worker_thread3 + 112 (queue.c:6104)
  15  libsystem_pthread.dylib        0x00000001826b306c _pthread_wqthread + 1268 (pthread.c:2286)
  16  libsystem_pthread.dylib        0x00000001826b2b6c start_wqthread + 4
  
  Thread 9 name:
  Thread 9:
  0   libsystem_kernel.dylib         0x00000001825817d0 stat + 8
  1   CFNetwork                      0x00000001831880ec DiskCookieStorage::syncStorageWithCompletionLocked(unsigned char, void () block_pointer) + 2200 (FilePath_Mac.h:53)
  2   CFNetwork                      0x0000000183181984 HTTPCookieStorage::syncStorageWithCompletion(unsigned char, void () block_pointer) + 140 (PrivateHTTPCookieStorage.h:99)
  3   CFNetwork                      0x0000000183181878 HTTPCookieStorage::_syncTimerFired(__CFRunLoopTimer*, void*) + 120 (HTTPCookieStorage.cpp:1177)
  4   CoreFoundation                 0x0000000182a33dc0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28 (CFRunLoop.c:1832)
  5   CoreFoundation                 0x0000000182a33ae4 __CFRunLoopDoTimer + 864 (CFRunLoop.c:2415)
  6   CoreFoundation                 0x0000000182a332e4 __CFRunLoopDoTimers + 248 (CFRunLoop.c:2562)
  7   CoreFoundation                 0x0000000182a30ecc __CFRunLoopRun + 1928 (CFRunLoop.c:3083)
  8   CoreFoundation                 0x0000000182950c58 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3245)
  9   CFNetwork                      0x000000018323fb08 -[__CoreSchedulingSetRunnable runForever] + 780 (CoreSchedulingSet.mm:1364)
  10  Foundation                     0x00000001834870f4 __NSThread__start__ + 996 (NSThread.m:1181)
  11  libsystem_pthread.dylib        0x00000001826b42b4 _pthread_body + 308 (pthread.c:740)
  12  libsystem_pthread.dylib        0x00000001826b4180 _pthread_start + 312 (pthread.c:799)
  13  libsystem_pthread.dylib        0x00000001826b2b74 thread_start + 4
  
  Thread 0 crashed with ARM Thread State (64-bit):
      x0: 0x0000000010004005   x1: 0x0000000007000806   x2: 0x0000000000000000   x3: 0x0000000000000c00
      x4: 0x0000000000002103   x5: 0x00000000ffffffff   x6: 0x0000000000000000   x7: 0x00000000001b4069
      x8: 0x00000000fffffbbf   x9: 0x0000000007000000  x10: 0x0000000007000100  x11: 0x0000000000000040
     x12: 0xffffffffffffffff  x13: 0x0000000000000001  x14: 0x005fb300005fb300  x15: 0x0000000000000000
     x16: 0xffffffffffffffe1  x17: 0x00000000ffffffff  x18: 0xfffffff01c4dd260  x19: 0x0000000000000000
     x20: 0x00000000ffffffff  x21: 0x0000000000002103  x22: 0x0000000000000c00  x23: 0x000000016f69ed18
     x24: 0x0000000007000806  x25: 0x0000000000000000  x26: 0x0000000007000806  x27: 0x0000000000000c00
     x28: 0x0000000000000001   fp: 0x000000016f69ec10   lr: 0x000000018257f3e0
      sp: 0x000000016f69ebc0   pc: 0x000000018257f568 cpsr: 0x60000000</code></pre>
  </div>
  </div>
  </p>