Try realm.write crashes (SIGABRT)


#1

Hello,

My app crashes after updating to the latest Realm version. The crash occurs after the first View Controller is loaded (ViewDidLoad) while trying to write to realm. The crash occurs before the function inside try realm.write {} is being executed.

I’m not sure how to interpret the error info, so I’m pasting everything here + I uploaded a screenshot:

libsystem_kernel.dylib`kevent:
    0x1ad10e914 <+0>:  mov    x16, #0x16b
    0x1ad10e918 <+4>:  svc    #0x80
->  0x1ad10e91c <+8>:  b.lo   0x1ad10e934               ; <+32>
    0x1ad10e920 <+12>: stp    x29, x30, [sp, #-0x10]!
    0x1ad10e924 <+16>: mov    x29, sp
    0x1ad10e928 <+20>: bl     0x1ad102800               ; cerror_nocancel
    0x1ad10e92c <+24>: mov    sp, x29
    0x1ad10e930 <+28>: ldp    x29, x30, [sp], #0x10
    0x1ad10e934 <+32>: ret

Here is how I declare my Realm variable:
lazy var realm = try! Realm()

And here is how I perform a write transaction (the code that crashes):

        do {
            try realm.write {
                deleteEmptyFolders()
            }
        } catch {
            print("Unable to delete empty folders: \(error)")
        }

Thank you.


(jay) #2

It’s generally best practice to include the code that actually crashed, enough to where we can duplicate the issue. Also, include code as text please, no images so if we need to test it we can copy/paste.

You may also want to add a breakpoint in your code, well before the crash, and step up to the crash inspecting your vars to see which one isn’t what you expected


#3

My bad. Below is the text in the picture:

Thread 1 Queue : com.apple.main-thread (serial)
#0 0x0000000101770264 in __abort_with_payload ()
#1 0x000000010176f8a4 in abort_with_payload_wrapper_internal ()
#2 0x000000010176f8d4 in abort_with_payload ()
#3 0x00000001017308f4 in dyld::halt(char const*) ()
#4 0x0000000101730a10 in dyld::fastBindLazySymbol(ImageLoader**, unsigned long) ()
#5 0x00000001acfc2bb0 in dyld_stub_binder ()
#6 0x000000010100ae60 in CategoriesViewController.embedTaskListInFolder(at:) at /Users/mac/App Development/Beyond/Beyond/Controllers/CategoriesViewController/CategoryTableView.swift:450
#7 0x000000010100ac3c in closure #1 in closure #1 in CategoriesViewController.tableView(_:leadingSwipeActionsConfigurationForRowAt:) at /Users/mac/App Development/Beyond/Beyond/Controllers/CategoriesViewController/CategoryTableView.swift:428
#8 0x0000000100f7819c in thunk for @escaping @callee_guaranteed (@guaranteed NSTimer) -> () ()
#9 0x00000001ae0285fc in __NSFireTimer ()
#10 0x00000001ad506bf0 in CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION ()
#11 0x00000001ad506920 in __CFRunLoopDoTimer ()
#12 0x00000001ad506154 in __CFRunLoopDoTimers ()
#13 0x00000001ad501030 in __CFRunLoopRun ()
#14 0x00000001ad5005b8 in CFRunLoopRunSpecific ()
#15 0x00000001af774584 in GSEventRunModal ()
#16 0x00000001d9dfb558 in UIApplicationMain ()
#17 0x0000000101123080 in main at /Users/mac/App Development/Beyond/Beyond/AppDelegate.swift:14
#18 0x00000001acfc0b94 in start ()
Thread 4#0 0x00000001ad194cfc in start_wqthread ()
com.apple.uikit.eventfetch-thread (6)#0 0x00000001ad101ed0 in mach_msg_trap ()
#1 0x00000001ad1013a8 in mach_msg ()
#2 0x00000001ad505fb0 in __CFRunLoopServiceMachPort ()
#3 0x00000001ad500e4c in __CFRunLoopRun ()
#4 0x00000001ad5005b8 in CFRunLoopRunSpecific ()
#5 0x00000001adef46a4 in -[NSRunLoop(NSRunLoop) runMode:beforeDate:] ()
#6 0x00000001adef4550 in -[NSRunLoop(NSRunLoop) runUntilDate:] ()
#7 0x00000001d9d58ac0 in -[UIEventFetcher threadMain] ()
#8 0x00000001ae0273b0 in NSThread__start ()
#9 0x00000001ad1912fc in _pthread_body ()
#10 0x00000001ad19125c in _pthread_start ()
#11 0x00000001ad194d08 in thread_start ()
Realm notification listener (11)#0 0x00000001ad10e91c in kevent ()
#1 0x0000000101b910b0 in realm::_impl::ExternalCommitHelper::listen() ()
#2 0x0000000101b95e40 in realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0::operator()() const ()
#3 0x0000000101b95ddc in decltype(std::__1::forwardrealm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0(fp)()) std::__1::__invokerealm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0(realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0&&) ()
#4 0x0000000101b95d3c in void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_deletestd::__1::__thread_struct >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_deletestd::__1::__thread_struct >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>&, std::__1::__tuple_indices<>) ()
#5 0x0000000101b95420 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_deletestd::__1::__thread_struct >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >(void*) ()
#6 0x00000001ad1912fc in _pthread_body ()
#7 0x00000001ad19125c in _pthread_start ()
#8 0x00000001ad194d08 in thread_start ()
Thread 12#0 0x00000001ad10db9c in __workq_kernreturn ()
#1 0x00000001ad192114 in _pthread_wqthread ()
#2 0x00000001ad194d00 in start_wqthread ()


#4

[Added the code that crashed in the first post]
I’m pretty new to swift and I’m not sure how to inspect the variables prior to the crash. What I did is I included print statements and noticed that deleteEmptyFolders doesn’t even get executed. The app crashes when I do a do { try realm.write {} }


#5

Note that I’m not including the deleteSection function code because even if it’s commented out, the app still crashes.


#6

I was able to fix my issues by reproducing the steps listed in the accepted answer of this thread:

Since the accepted answer’s side effects have been removed by a script written by Kyle Fuller - deintegrate, I’ll post the proper workflow here:

Install clean:

$ sudo gem install cocoapods-clean
Run deintegrate in the folder of the project:

$ pod deintegrate

Clean:

$ pod clean

Modify your podfile (delete the lines with the pods you don’t want to use anymore) and run:

$ pod install

Done.