ios - `NSPersistentStoreCoordinator removePersistentStore:` hangs when using permanent object IDs -
i came across issue in our application caused use of temporary nsmanagedobjectids
. in response network requests, mapping operation inserts managed objects private queue moc, saved way root moc (the 1 persistentstorecoordinator
assigned).
we aware not obtaining permanent ids may cause issues, hadn't come across problems, stuck it.
i stumbled across issue temporary ids , made switch obtain permanent ids. clear: every time insert new objects part of our mapping operation, obtain permanent ids.
the issue solved, happy days! not fast... under ios 7.1 (8.4 works fine), calls nspersistentstorecoordinator removepersistentstore:
hang, indefinitely. part of our core data stack teardown when user logs out (to clear data).
here's relevant code our persistence manager:
- (void)reset { fcyweakifyself; [self.managedobjectcontext performblockandwait:^{ fcystrongifyselfinto(strongself); strongself.managedobjectcontext = nil; strongself.persistentstoremanagedobjectcontext = nil; (nspersistentstore *store in strongself.persistentstorecoordinator.persistentstores) { nserror *error = nil; bool didremovestore = [strongself.persistentstorecoordinator removepersistentstore:store error:&error]; fcyassert(didremovestore, @"failed remove persistent store: %@\n%@", [error localizeddescription], [error userinfo]); } strongself.persistentstorecoordinator = nil; strongself.managedobjectmodel = nil; }]; [self initializecoredata]; [self notifydelegates]; } - (void)initializecoredata { fcyassert(!self.managedobjectmodel, @"coredata has been initialized"); nsbundle *bundle = [nsbundle bundleforclass:[ttpersistencemanager class]]; self.managedobjectmodel = [nsmanagedobjectmodel mergedmodelfrombundles:@[bundle]]; self.persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:self.managedobjectmodel]; nserror *error = nil; nspersistentstore *store = [self.persistentstorecoordinator addpersistentstorewithtype:[self storagetype] configuration:nil url:nil options:nil error:&error]; fcyassert(store != nil, @"failed create persistent store: %@\n%@", [error localizeddescription], [error userinfo]); self.persistentstoremanagedobjectcontext = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:nsprivatequeueconcurrencytype]; self.persistentstoremanagedobjectcontext.persistentstorecoordinator = self.persistentstorecoordinator; self.persistentstoremanagedobjectcontext.mergepolicy = nsmergebypropertystoretrumpmergepolicy; self.managedobjectcontext = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:nsmainqueueconcurrencytype]; self.managedobjectcontext.parentcontext = self.persistentstoremanagedobjectcontext; self.managedobjectcontext.mergepolicy = nsmergebypropertystoretrumpmergepolicy; }
when app hung , stop execution, backtrace:
* thread #1: tid = 0x38ee8e, 0x0000000112f6551a libsystem_kernel.dylib`semaphore_wait_trap + 10, queue = 'com.apple.main-thread', stop reason = signal sigstop * frame #0: 0x0000000112f6551a libsystem_kernel.dylib`semaphore_wait_trap + 10 frame #1: 0x0000000112bde7b4 libdispatch.dylib`_dispatch_thread_semaphore_wait + 16 frame #2: 0x0000000112bdc3a2 libdispatch.dylib`_dispatch_barrier_sync_f_slow + 321 frame #3: 0x000000010fb08f92 coredata`_perform + 114 frame #4: 0x000000010fb0b7b8 coredata`-[nsmanagedobjectcontext(_nestedcontextsupport) managedobjectcontextdidunregisterobjectswithids:] + 72 frame #5: 0x000000010fae0d2a coredata`-[_pfmanagedobjectreferencequeue _processreferencequeue:] + 1706 frame #6: 0x000000010fb0ff33 coredata`-[nsmanagedobjectcontext(_nsinternalnotificationhandling) _processchangedstoreconfigurationnotification:] + 2771 frame #7: 0x000000010fb71ee4 coredata`__95-[nsmanagedobjectcontext(_nsinternalnotificationhandling) _sendorenqueuenotification:selector:]_block_invoke + 84 frame #8: 0x000000010fb08c7b coredata`developersubmittedblocktonsmanagedobjectcontextperform + 107 frame #9: 0x000000010fb08bc4 coredata`-[nsmanagedobjectcontext performblockandwait:] + 132 frame #10: 0x000000010fb0f2f7 coredata`-[nsmanagedobjectcontext(_nsinternalnotificationhandling) _sendorenqueuenotification:selector:] + 231 frame #11: 0x000000011289dd9c corefoundation`__cfnotificationcenter_is_calling_out_to_an_observer__ + 12 frame #12: 0x000000011280051d corefoundation`_cfxnotificationpost + 2381 frame #13: 0x000000011027e7fa foundation`-[nsnotificationcenter postnotificationname:object:userinfo:] + 68 frame #14: 0x000000010fac06bc coredata`-[nspersistentstorecoordinator(_nsinternalmethods) _poststoreschangednotificationsforstores:changekey:options:] + 220 frame #15: 0x000000010fb0e5d6 coredata`-[nspersistentstorecoordinator removepersistentstore:error:] + 278 frame #16: 0x000000010e4bc430 wingtip`__29-[ttpersistencemanager reset]_block_invoke(.block_descriptor=<unavailable>) + 528 @ ttpersistencemanager.m:67 frame #17: 0x000000010fb08c7b coredata`developersubmittedblocktonsmanagedobjectcontextperform + 107 frame #18: 0x000000010fb08bc4 coredata`-[nsmanagedobjectcontext performblockandwait:] + 132 frame #19: 0x000000010e4bc17d wingtip`-[ttpersistencemanager reset](self=0x00007ff441604e50, _cmd=0x0000000118cfb867) + 237 @ ttpersistencemanager.m:59 frame #20: 0x000000010e1dee19 wingtip`-[wtgatekeeper resetpersistencemanager](self=0x00007ff44195a520, _cmd=0x000000010e8c079e) + 121 @ wtgatekeeper.m:118 frame #21: 0x000000011283df1c corefoundation`__invoking___ + 140 frame #22: 0x000000011283ddc4 corefoundation`-[nsinvocation invoke] + 308 frame #23: 0x000000010e48d141 wingtip`-[ttstatemachine calltargetswithevent:state:](self=0x00007ff44177d2f0, _cmd=0x000000010e8e89a5, event=ttstatemachineeventdidenter, state=0x000000010ea12f28) + 977 @ ttstatemachine.m:277 frame #24: 0x000000010e48aa59 wingtip`-[ttstatemachine transitiontostate:error:](self=0x00007ff44177d2f0, _cmd=0x000000010e8c0919, state=0x000000010ea12f28, error=0x00007fff51a2d168) + 521 @ ttstatemachine.m:105 frame #25: 0x000000010e1e0a66 wingtip`-[wtauthenticationstatemachine transitiontostate:error:](self=0x00007ff44177d2f0, _cmd=0x000000010e8c0919, state=0x000000010ea12f28, error=0x00007fff51a2d168) + 454 @ wtauthenticationstatemachine.m:91 frame #26: 0x000000010e48ac08 wingtip`-[ttstatemachine transitiontostate:](self=0x00007ff44177d2f0, _cmd=0x000000010e8c0746, state=0x000000010ea12f28) + 168 @ ttstatemachine.m:119 frame #27: 0x000000010e1e3118 wingtip`__33-[wtauthenticatebehavior signout]_block_invoke(.block_descriptor=<unavailable>, alertview=0x00007ff448075eb0, buttonindex=1) + 440 @ wtauthenticatebehavior.m:134 frame #28: 0x000000010e4513ac wingtip`-[mtblockalertview alertview:diddismisswithbuttonindex:](self=0x00007ff448075eb0, _cmd=0x00000001116a1fae, alertview=0x00007ff448075eb0, buttonindex=1) + 108 @ mtblockalertview.m:77 frame #29: 0x0000000111436451 uikit`-[uialertview modalitem:diddismisswithbuttonindex:] + 115 frame #30: 0x00000001114eea63 uikit`__87-[_uimodalitemscoordinator _dismissitem:withtappedbuttonindex:animated:notifydelegate:]_block_invoke237 + 120 frame #31: 0x0000000111139d32 uikit`__105-[_uimodalitemspresentingviewcontroller _dismissitem:andpresentitem:animated:completion:keepdimmingview:]_block_invoke256 + 651 frame #32: 0x00000001110206e8 uikit`-[uiviewanimationblockdelegate _didendblockanimation:finished:context:] + 299 frame #33: 0x000000011100c68e uikit`-[uiviewanimationstate senddelegateanimationdidstop:finished:] + 235 frame #34: 0x000000011100c941 uikit`-[uiviewanimationstate animationdidstop:finished:] + 78 frame #35: 0x0000000110c62134 quartzcore`ca::layer::run_animation_callbacks(void*) + 310 frame #36: 0x0000000112bed72d libdispatch.dylib`_dispatch_client_callout + 8 frame #37: 0x0000000112bdd3fc libdispatch.dylib`_dispatch_main_queue_callback_4cf + 354 frame #38: 0x00000001128a6289 corefoundation`__cfrunloop_is_servicing_the_main_dispatch_queue__ + 9 frame #39: 0x00000001127f3854 corefoundation`__cfrunlooprun + 1764 frame #40: 0x00000001127f2d83 corefoundation`cfrunlooprunspecific + 467 frame #41: 0x0000000113a0df04 graphicsservices`gseventrunmodal + 161 frame #42: 0x0000000110fc7e33 uikit`uiapplicationmain + 1010 frame #43: 0x000000010e1d1e02 wingtip`main(argc=3, argv=0x00007fff51a2e4a0) + 370 @ main.m:19 frame #44: 0x0000000112e3d5c9 libdyld.dylib`start + 1
my best guess within app still holding strong reference managed object, , because of permanent object id, it's retaining persistent store coordinator.
if case, i'd expect common issue. unfortunately i'm unable find similar on www.
any appreciated!
Comments
Post a Comment