Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible corrupt realm database. Crashes on start for some users after RealmSwift 2.0.3 #4302

Closed
fishfisher opened this issue Nov 7, 2016 · 18 comments
Labels

Comments

@fishfisher
Copy link

fishfisher commented Nov 7, 2016

After updating to Realm 2.0.3 I am seeing a lot of crash reports that I do not understand much of, and users are reporting that they are not able to open the app.
I don’t even know where to start when it comes to troubleshooting this issue. Please let me know what you need from me for troubleshooting!

The app uses a Today Extension with a shared realm.

Goals

Help with troubleshooting to identify the source of the issue

Expected Results

App not to crash

Actual Results

Crash on start.
Most of the crashes looks the same. I will add the partial stacktrace for some of them.


Crashed: com.apple.main-thread
0  Realm                          0x100bbbca8 realm::Array::init_from_mem(realm::MemRef) + 28
1  Realm                          0x100bbc140 realm::Array::update_from_parent(unsigned long) + 108
2  Realm                          0x100bbc140 realm::Array::update_from_parent(unsigned long) + 108
3  Realm                          0x100c51244 realm::StringColumn::update_from_parent(unsigned long) + 108
4  Realm                          0x100cef8d0 realm::Table::update_from_parent(unsigned long) + 136
5  Realm                          0x100c603d0 realm::Group::update_refs(unsigned long, unsigned long) + 176
6  Realm                          0x100c6b540 realm::SharedGroup::commit_and_continue_as_read() + 244
7  Realm                          0x100b50138 realm::_impl::transaction::commit(realm::SharedGroup&, realm::BindingContext*) + 24
8  Realm                          0x100b45c34 realm::Realm::commit_transaction() + 64
9  Realm                          0x100b27d90 -[RLMRealm commitWriteTransaction:] + 32
10 RealmSwift                     0x10100ac84 _TFC10RealmSwift5Realm5writefzFzT_T_T_ + 220

****

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x18d2fa014 __pthread_kill + 8
1  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
2  libsystem_c.dylib              0x18d26e3f4 abort + 140
3  Realm                          0x100c464d4 please_report_this_error_to_help_at_realm_dot_io + 10
4  Realm                          0x100c46794 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 232
5  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
6  Realm                          0x100c46920 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 368
7  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
8  Realm                          0x100b288b8 void realm::util::terminate<realm::Array::WidthType, realm::Array::WidthType>(char const*, char const*, long, realm::Array::WidthType, realm::Array::WidthType) + 58
9  Realm                          0x100c4fd3c realm::Array::calc_byte_len(unsigned long, unsigned long) const + 70
10 Realm                          0x100c4bfc4 realm::Array::copy_on_write() + 68
11 Realm                          0x100c4cc90 realm::Array::set(unsigned long, long long) + 48
12 Realm                          0x100b24850 realm::BpTree<long long>::move_last_over(unsigned long, unsigned long) + 52
13 Realm                          0x100cec934 realm::TimestampColumn::move_last_row_over(unsigned long, unsigned long, bool) + 248
14 Realm                          0x100d713c0 realm::Table::erase_row(unsigned long, bool) + 592
15 Realm                          0x100b53b28 RLMTrackDeletions(RLMRealm*, void () block_pointer) + 388
16 Realm                          0x100b51a28 RLMDeleteObjectFromRealm + 168
17 RealmSwift                     0x10109b714 _TFC10RealmSwift5Realm6deletefCS_6ObjectT_ + 24
18 myRoster                       0x1000eb760 partial apply for static FlightInfo.(deleteCache([String]) throws -> ()).(closure #1) (FlightInfo.swift)
19 RealmSwift                     0x10109abf4 _TFC10RealmSwift5Realm5writefzFzT_T_T_ + 76

****

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x18d2fa014 __pthread_kill + 8
1  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
2  libsystem_c.dylib              0x18d26e3f4 abort + 140
3  Realm                          0x100bda4d4 please_report_this_error_to_help_at_realm_dot_io + 10
4  Realm                          0x100bda794 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 232
5  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
6  Realm                          0x100bda920 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 368
7  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
8  Realm                          0x100abc8b8 void realm::util::terminate<realm::Array::WidthType, realm::Array::WidthType>(char const*, char const*, long, realm::Array::WidthType, realm::Array::WidthType) + 58
9  Realm                          0x100be3d3c realm::Array::calc_byte_len(unsigned long, unsigned long) const + 70
10 Realm                          0x100bdffc4 realm::Array::copy_on_write() + 68
11 Realm                          0x100be0c90 realm::Array::set(unsigned long, long long) + 48
12 Realm                          0x100d03160 realm::Table::set_timestamp(unsigned long, unsigned long, realm::Timestamp, bool) + 288
13 Realm                          0x100acec3c RLMSetValue(RLMObjectBase*, unsigned long, NSDate*, bool) + 388
14 Realm                          0x100acea7c ___ZL13RLMMakeSetterIU8__strongP6NSDateS2_EPFvvEP11RLMProperty_block_invoke_2 + 248

****

Crashed: com.apple.root.default-qos
0  libsystem_kernel.dylib         0x258fec5c __pthread_kill + 8
1  libsystem_pthread.dylib        0x259a8733 pthread_kill + 62
2  libsystem_c.dylib              0x258930ad abort + 108
3  Realm                          0xbb74b9 please_report_this_error_to_help_at_realm_dot_io + 6
4  Realm                          0xbb780b realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 314
5  Realm                          0xbb7a2d realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 528
6  Realm                          0xa8336f void realm::util::terminate<unsigned long, unsigned long>(char const*, char const*, long, unsigned long, unsigned long) + 46
7  Realm                          0xae2ba9 realm::LinkView::get(unsigned long) + 104
8  Realm                          0xa82983 realm::List::get_unchecked(unsigned long) const + 16
9  Realm                          0xab05ed -[RLMFastEnumerator countByEnumeratingWithState:count:] + 412
10 Realm                          0xaab8b3 -[RLMArrayLinkView countByEnumeratingWithState:objects:count:] + 250
11 libswiftFoundation.dylib       0x17cee84 _TTSf4n_g___TFFC10Foundation25NSFastEnumerationIterator7refreshFT_T_U_FRGSrGSqGVs9UnmanagedPs9AnyObject____T_ + 144
12 libswiftFoundation.dylib       0x176248c _TFC10Foundation25NSFastEnumerationIterator4nextfT_GSqP__ + 152
13 RealmSwift                     0xfeee24 _TFC10RealmSwift11RLMIterator4nextfT_GSqx_ + 28
14 RealmSwift                     0xfcb7b0 _TTWuRxC10RealmSwift6ObjectrGCS_11RLMIteratorx_s16IteratorProtocolS_FS2_4nextfT_GSqwx7Element_ + 32

Steps to Reproduce

I do not know the steps to reproduce as only about 0.01 % of the users are experiencing these crashes.

Version of Realm and Tooling

Realm version: 2.0.3

Xcode version: XCode 8

iOS/OSX version: iOS 9.3.5 - 10.1.1

Dependency manager + version: CocoaPods

@jpsim
Copy link
Contributor

jpsim commented Nov 7, 2016

Thanks for reporting this @fishfisher. Could you please share the Crashlytics logs included in your crash reports? realm::util::terminate logs an assertion message which is useful in determining the reason for the assertion failure.

Realm folks: Also tracking this in Helpscout

#4273 also has an assertion failure in LinkView::get, though it's very hard to say if they're related at the moment. Leaning towards no.

@fishfisher
Copy link
Author

fishfisher commented Nov 7, 2016

Thanks for reporting back.

Here is the full stack trace of one of the crashes:

Crashlytics - plaintext stacktrace downloaded by Erik at Mon, 07 Nov 2016 22:53:31 GMT
Platform: ios
Date: 2016-11-06T22:54:22Z
OS Version: 10.0.2 (14A456)
Device: iPhone 6
RAM Free: 5.4%
Disk Free: 52.1%

—

#73
FlightInfo.swift line 0
partial apply for static FlightInfo.(deleteCache([String]) throws -> ()).(closure #1)

—

#0. Crashed: com.apple.main-thread
    SIGABRT ABORT 0x000000018d2fa014
0  libsystem_kernel.dylib         0x18d2fa014 __pthread_kill + 8
1  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
2  libsystem_c.dylib              0x18d26e3f4 abort + 140
3  Realm                          0x100c464d4 please_report_this_error_to_help_at_realm_dot_io + 10
4  Realm                          0x100c46794 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 232
5  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
6  Realm                          0x100c46920 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 368
7  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
8  Realm                          0x100b288b8 void realm::util::terminate<realm::Array::WidthType, realm::Array::WidthType>(char const*, char const*, long, realm::Array::WidthType, realm::Array::WidthType) + 58
9  Realm                          0x100c4fd3c realm::Array::calc_byte_len(unsigned long, unsigned long) const + 70
10 Realm                          0x100c4bfc4 realm::Array::copy_on_write() + 68
11 Realm                          0x100c4cc90 realm::Array::set(unsigned long, long long) + 48
12 Realm                          0x100b24850 realm::BpTree<long long>::move_last_over(unsigned long, unsigned long) + 52
13 Realm                          0x100cec934 realm::TimestampColumn::move_last_row_over(unsigned long, unsigned long, bool) + 248
14 Realm                          0x100d713c0 realm::Table::erase_row(unsigned long, bool) + 592
15 Realm                          0x100b53b28 RLMTrackDeletions(RLMRealm*, void () block_pointer) + 388
16 Realm                          0x100b51a28 RLMDeleteObjectFromRealm + 168
17 RealmSwift                     0x10109b714 _TFC10RealmSwift5Realm6deletefCS_6ObjectT_ + 24
18 MyApp                          0x1000eb760 partial apply for static FlightInfo.(deleteCache([String]) throws -> ()).(closure #1) (FlightInfo.swift)
19 RealmSwift                     0x10109abf4 _TFC10RealmSwift5Realm5writefzFzT_T_T_ + 76
20 MyApp                          0x1000e33d8 specialized static FlightInfo.deleteCache([String]) throws -> () (FlightInfo.swift:560)
21 MyApp                          0x10015e4a0 specialized specialized static FlightInfoHelper.updateFlightInfoForTodaysDuties(NSManagedObjectContext?, updateSecondsInterval : Double, completion : (Bool) -> ()) -> () + 4295582880
22 MyApp                          0x10035e514 specialized AppDelegate.applicationDidBecomeActive(UIApplication) -> () (AppDelegate.swift)
23 MyApp                          0x100353da4 @objc AppDelegate.applicationDidBecomeActive(UIApplication) -> () (AppDelegate.swift)
24 UIKit                          0x1941fa248 -[UIApplication _stopDeactivatingForReason:] + 1152
25 UIKit                          0x1943fdd20 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2744
26 UIKit                          0x194412080 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3134 + 48
27 UIKit                          0x1943fa8c4 -[UIApplication workspaceDidEndTransaction:] + 168
28 FrontBoardServices             0x18fecd8bc __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
29 FrontBoardServices             0x18fecd728 -[FBSSerialQueue _performNext] + 176
30 FrontBoardServices             0x18fecdad0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
31 CoreFoundation                 0x18e2da278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
32 CoreFoundation                 0x18e2d9bc0 __CFRunLoopDoSources0 + 524
33 CoreFoundation                 0x18e2d77c0 __CFRunLoopRun + 804
34 CoreFoundation                 0x18e206048 CFRunLoopRunSpecific + 444
35 UIKit                          0x1941e05dc -[UIApplication _run] + 608
36 UIKit                          0x1941db360 UIApplicationMain + 208
37 MyApp                          0x1000dd938 main (AppDelegate.swift:18)
38 libdispatch.dylib              0x18d1e85b8 (Missing)

--

#0. Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x18d2fa014 __pthread_kill + 8
1  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
2  libsystem_c.dylib              0x18d26e3f4 abort + 140
3  Realm                          0x100c464d4 please_report_this_error_to_help_at_realm_dot_io + 10
4  Realm                          0x100c46794 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 232
5  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
6  Realm                          0x100c46920 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 368
7  libsystem_pthread.dylib        0x18d3c1460 pthread_kill + 112
8  Realm                          0x100b288b8 void realm::util::terminate<realm::Array::WidthType, realm::Array::WidthType>(char const*, char const*, long, realm::Array::WidthType, realm::Array::WidthType) + 58
9  Realm                          0x100c4fd3c realm::Array::calc_byte_len(unsigned long, unsigned long) const + 70
10 Realm                          0x100c4bfc4 realm::Array::copy_on_write() + 68
11 Realm                          0x100c4cc90 realm::Array::set(unsigned long, long long) + 48
12 Realm                          0x100b24850 realm::BpTree<long long>::move_last_over(unsigned long, unsigned long) + 52
13 Realm                          0x100cec934 realm::TimestampColumn::move_last_row_over(unsigned long, unsigned long, bool) + 248
14 Realm                          0x100d713c0 realm::Table::erase_row(unsigned long, bool) + 592
15 Realm                          0x100b53b28 RLMTrackDeletions(RLMRealm*, void () block_pointer) + 388
16 Realm                          0x100b51a28 RLMDeleteObjectFromRealm + 168
17 RealmSwift                     0x10109b714 _TFC10RealmSwift5Realm6deletefCS_6ObjectT_ + 24
18 MyApp                          0x1000eb760 partial apply for static FlightInfo.(deleteCache([String]) throws -> ()).(closure #1) (FlightInfo.swift)
19 RealmSwift                     0x10109abf4 _TFC10RealmSwift5Realm5writefzFzT_T_T_ + 76
20 MyApp                          0x1000e33d8 specialized static FlightInfo.deleteCache([String]) throws -> () (FlightInfo.swift:560)
21 MyApp                          0x10015e4a0 specialized specialized static FlightInfoHelper.updateFlightInfoForTodaysDuties(NSManagedObjectContext?, updateSecondsInterval : Double, completion : (Bool) -> ()) -> () + 4295582880
22 MyApp                          0x10035e514 specialized AppDelegate.applicationDidBecomeActive(UIApplication) -> () (AppDelegate.swift)
23 MyApp                          0x100353da4 @objc AppDelegate.applicationDidBecomeActive(UIApplication) -> () (AppDelegate.swift)
24 UIKit                          0x1941fa248 -[UIApplication _stopDeactivatingForReason:] + 1152
25 UIKit                          0x1943fdd20 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2744
26 UIKit                          0x194412080 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3134 + 48
27 UIKit                          0x1943fa8c4 -[UIApplication workspaceDidEndTransaction:] + 168
28 FrontBoardServices             0x18fecd8bc __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
29 FrontBoardServices             0x18fecd728 -[FBSSerialQueue _performNext] + 176
30 FrontBoardServices             0x18fecdad0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
31 CoreFoundation                 0x18e2da278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
32 CoreFoundation                 0x18e2d9bc0 __CFRunLoopDoSources0 + 524
33 CoreFoundation                 0x18e2d77c0 __CFRunLoopRun + 804
34 CoreFoundation                 0x18e206048 CFRunLoopRunSpecific + 444
35 UIKit                          0x1941e05dc -[UIApplication _run] + 608
36 UIKit                          0x1941db360 UIApplicationMain + 208
37 MyApp                          0x1000dd938 main (AppDelegate.swift:18)
38 libdispatch.dylib              0x18d1e85b8 (Missing)

#1. Thread
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3bd36c _pthread_wqthread + 1452
2  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#2. Thread
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3bd36c _pthread_wqthread + 1452
2  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#3. com.apple.network.resolver_queue
0  libsystem_kernel.dylib         0x18d2fbe80 shutdown + 8
1  libsystem_dnssd.dylib          0x18d2b1fd4 DNSServiceRefDeallocate + 280
2  libsystem_network.dylib        0x18d3730a8 nw_resolver_cancel_query_on_queue + 48
3  libsystem_network.dylib        0x18d37297c nw_resolver_update_status_on_queue + 440
4  libsystem_network.dylib        0x18d371df4 nw_resolver_host_resolve_callback + 656
5  libsystem_dnssd.dylib          0x18d2b3668 handle_addrinfo_response + 424
6  libsystem_dnssd.dylib          0x18d2b1938 DNSServiceProcessResult + 624
7  libdispatch.dylib              0x18d1b51c0 _dispatch_client_callout + 16
8  libdispatch.dylib              0x18d1c2008 _dispatch_continuation_pop + 576
9  libdispatch.dylib              0x18d1ce648 _dispatch_source_latch_and_call + 204
10 libdispatch.dylib              0x18d1b7164 _dispatch_source_invoke + 820
11 libdispatch.dylib              0x18d1c3278 _dispatch_queue_serial_drain + 468
12 libdispatch.dylib              0x18d1b89a8 _dispatch_queue_invoke + 652
13 libdispatch.dylib              0x18d1c42ac _dispatch_root_queue_drain_deferred_item + 248
14 libdispatch.dylib              0x18d1cab0c _dispatch_kevent_worker_thread + 816
15 libsystem_pthread.dylib        0x18d3bd174 _pthread_wqthread + 948
16 libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#4. Thread
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3bd36c _pthread_wqthread + 1452
2  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#5. Thread
0  libsystem_pthread.dylib        0x18d3bcdb0 start_wqthread + 126

#6. com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x18d2dc16c mach_msg_trap + 8
1  libsystem_kernel.dylib         0x18d2dbfdc mach_msg + 72
2  CoreFoundation                 0x18e2d9cec __CFRunLoopServiceMachPort + 192
3  CoreFoundation                 0x18e2d7908 __CFRunLoopRun + 1132
4  CoreFoundation                 0x18e206048 CFRunLoopRunSpecific + 444
5  Foundation                     0x18ed14b1c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6  Foundation                     0x18ed3560c -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7  UIKit                          0x194b55c7c -[UIEventFetcher threadMain] + 136
8  Foundation                     0x18ee1250c __NSThread__start__ + 1024
9  libsystem_pthread.dylib        0x18d3bf860 _pthread_body + 240
10 libsystem_pthread.dylib        0x18d3bf770 _pthread_body + 282
11 libsystem_pthread.dylib        0x18d3bcdbc thread_start + 4

#7. RLMRealm notification listener
0  libsystem_kernel.dylib         0x18d2e0630 kevent + 8
1  Realm                          0x100b1213c realm::_impl::ExternalCommitHelper::listen() + 200
2  Realm                          0x100b131fc std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>::operator()() + 28
3  Realm                          0x100b13184 std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::__execute() + 28
4  Realm                          0x100b1334c std::__1::__thread_proxy<std::__1::tuple<void (std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0> >*> >(void*, void*) + 84
5  libsystem_pthread.dylib        0x18d3bf860 _pthread_body + 240
6  libsystem_pthread.dylib        0x18d3bf770 _pthread_body + 282
7  libsystem_pthread.dylib        0x18d3bcdbc thread_start + 4

#8. Thread
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3bd36c _pthread_wqthread + 1452
2  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#9. com.twitter.crashlytics.ios.MachExceptionServer
0  libsystem_kernel.dylib         0x18d2dc16c mach_msg_trap + 8
1  libsystem_kernel.dylib         0x18d2dbfdc mach_msg + 72
2  MyApp                          0x1003970e4 CLSMachExceptionServer + 4297912548
3  libsystem_pthread.dylib        0x18d3bf860 _pthread_body + 240
4  libsystem_pthread.dylib        0x18d3bf770 _pthread_body + 282
5  libsystem_pthread.dylib        0x18d3bcdbc thread_start + 4

#10. com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x18d2dc16c mach_msg_trap + 8
1  libsystem_kernel.dylib         0x18d2dbfdc mach_msg + 72
2  libdispatch.dylib              0x18d1cb87c _dispatch_mach_send_and_wait_for_reply + 516
3  libdispatch.dylib              0x18d1cbcc4 dispatch_mach_send_with_result_and_wait_for_reply + 60
4  libxpc.dylib                   0x18d401fe0 xpc_connection_send_message_with_reply_sync + 196
5  CoreTelephony                  0x190d5d360 SendXpcMessageIf(bool, __CTServerConnection*, xpc::dict const&, xpc::dict&) + 40
6  CoreTelephony                  0x190d63fdc _CTServerConnectionGetCellularDataIsEnabled + 220
7  CFNetwork                      0x18ea5585c _GetConnectionError(unsigned char) + 96
8  CFNetwork                      0x18ea55564 HTTPProtocol::transformErrorDomainNativeSocket(long) + 136
9  CFNetwork                      0x18ea4d648 HTTPProtocol::failWithStreamError(CFStreamError const*) + 172
10 CFNetwork                      0x18ea4d3bc ___ZN12HTTPProtocol17handleStreamErrorE13CFStreamErrorPK14__CFDictionary_block_invoke + 52
11 CFNetwork                      0x18ea4d374 HTTPProtocol::handleStreamError(CFStreamError, __CFDictionary const*) + 116
12 CFNetwork                      0x18ea17c94 TubeManager::_onqueue_newTubeReady(Tube*, CFStreamError) + 588
13 CFNetwork                      0x18ea179fc ___ZN11TubeManager12newTubeReadyEP4Tube13CFStreamError_block_invoke + 68
14 libdispatch.dylib              0x18d1b51c0 _dispatch_client_callout + 16
15 libdispatch.dylib              0x18d1c0b24 _dispatch_block_invoke_direct + 376
16 CFNetwork                      0x18eb46e98 RunloopBlockContext::_invoke_block(void const*, void*) + 36
17 CoreFoundation                 0x18e2059a8 CFArrayApplyFunction + 68
18 CFNetwork                      0x18eb46d7c RunloopBlockContext::perform() + 136
19 CFNetwork                      0x18eb480a4 MultiplexerSource::perform() + 312
20 CFNetwork                      0x18eb47e10 MultiplexerSource::_perform(void*) + 64
21 CoreFoundation                 0x18e2da278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
22 CoreFoundation                 0x18e2d9bc0 __CFRunLoopDoSources0 + 524
23 CoreFoundation                 0x18e2d77c0 __CFRunLoopRun + 804
24 CoreFoundation                 0x18e206048 CFRunLoopRunSpecific + 444
25 CFNetwork                      0x18e9f3cec +[NSURLConnection(Loader) _resourceLoadLoop:] + 336
26 Foundation                     0x18ee1250c __NSThread__start__ + 1024
27 libsystem_pthread.dylib        0x18d3bf860 _pthread_body + 240
28 libsystem_pthread.dylib        0x18d3bf770 _pthread_body + 282
29 libsystem_pthread.dylib        0x18d3bcdbc thread_start + 4

#11. com.apple.root.default-qos.overcommit
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3c1d6c _pthread_workqueue_addthreads + 72
2  libdispatch.dylib              0x18d1c65e0 _dispatch_global_queue_poke_slow + 60
3  libdispatch.dylib              0x18d1c534c _dispatch_root_queue_drain + 508
4  libdispatch.dylib              0x18d1c50ec _dispatch_worker_thread3 + 124
5  libsystem_pthread.dylib        0x18d3bd2c8 _pthread_wqthread + 1288
6  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#12. Thread
0  libsystem_pthread.dylib        0x18d3bcdb0 start_wqthread + 126

#13. Thread
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3bd36c _pthread_wqthread + 1452
2  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

#14. Thread
0  libsystem_kernel.dylib         0x18d2faa88 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18d3bd188 _pthread_wqthread + 968
2  libsystem_pthread.dylib        0x18d3bcdb4 start_wqthread + 4

@fishfisher
Copy link
Author

fishfisher commented Nov 8, 2016

@jpsim

Allrighty, after a lot of head scratching I have progressed a bit:

I have narrowed down that the crash is happening in the setup of the realm config in 'didFinishLaunchingWithOptions'. At let _ = try! Realm()..

I use the following code to set up the default realm. I'm basically checking that the standard realm exists and if it does I move it to a shared location so it can be accessible from my extension.
This is the code for the setup:

class func migrateAndSetDefaultRealmToSharedLocation() {

        if let pathForSharedGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.erik.myapp") {

            var config = Realm.Configuration(
                // Set the new schema version. This must be greater than the previously used
                // version (if you've never set a schema version before, the version is 0).
                schemaVersion: 15,

                // Set the block which will be called automatically when opening a Realm with
                // a schema version lower than the one set above
                migrationBlock: { migration, oldSchemaVersion in
                    // We haven’t migrated anything yet, so oldSchemaVersion == 0
                    if (oldSchemaVersion < 1) {
                        // Nothing to do!
                        // Realm will automatically detect new properties and removed properties
                        // And will update the schema on disk automatically
                    }

            })

            let sharedRealm = pathForSharedGroup.appendingPathComponent("default")

            let fullURL = sharedRealm.appendingPathExtension("realm")

            let fullPath = sharedRealm.appendingPathExtension("realm").path

            //print("Path for shared: \(fullPath)")

            //Check if it already exists, if it does not, copy the default realm to its location
            if FileManager.default.fileExists(atPath: fullPath) {

                //print("File exists in shared. No need to do anything else.")
            }
            else if let existingURLForDefaultRealm = config.fileURL {

                //Copy the default database to the shared location
                do {
                    try FileManager.default.copyItem(at: existingURLForDefaultRealm, to: fullURL)

                    print("Default realm was copied to shared location")

                    //Remove the old database
                    do {
                        try FileManager.default.removeItem(at: existingURLForDefaultRealm)

                        print("Default realm was deleted from Documents location.")

                    } catch let err {
                        print("Error deleting default realm: \(err)")
                    }

                } catch let err {
                    print("Error copying default realm to shared location: \(err)")
                }

            }

            config.fileURL = fullURL


            // Set this as the configuration used for the default Realm
            Realm.Configuration.defaultConfiguration = config

            // Now that we've told Realm how to handle the schema change, opening the file
            // will automatically perform the migration
            let _ = try! Realm()
        }
        else {
            print("Unable to set default realm to shared group.")
        }

    }

This is how I was able to identify where the crash happened:
I got in contact with one of the affected users, sent him a TestFlight build where I stripped out the setup of the shared realm. I had then implemented a code that would locate the realm in the shared group container and send that as an attatchment to my email.

I now have that realm-file and it crashes the Realm browser when I try to open it.
Can I send this file to someone at Realm so they can identify what is happening? The file may contain user sensitive data.

Regards,
Erik

@jpsim
Copy link
Contributor

jpsim commented Nov 8, 2016

I now have that realm-file and it crashes the Realm browser when I try to open it.
Can I send this file to someone at Realm so they can identify what is happening? The file may contain user sensitive data.

Yes! Could you please email the file to [email protected] referencing this issue? We'll take a closer look at it.

@fishfisher
Copy link
Author

Thank you for your quick reply! Mail sent!

@jpsim jpsim added Blocked This issue is blocked by another issue S:On Hold and removed Reproduction-Required labels Nov 8, 2016
@finnschiermer
Copy link

finnschiermer commented Nov 10, 2016

@fishfisher A perhaps dumb question: what is the Today Extension doing at the time the error occurs?

@fishfisher
Copy link
Author

@finnschiermer No, not at all. But, unforunately, I don't know much about the status of the Today Extension as the crash occurs. I have done a lot of testing with the extension together with launching the app, but I have not been able to reproduce. I have suspecing a conflict with the extension.

@fishfisher
Copy link
Author

Just some further thoughts around my issue.. As you can see in my migration class I look for pathForSharedGroup. If it is not found (which I though could not be possible), I do not migrate and a crash will happen when the un-migrated realm is accessed. Can this be a cause for the issue? If so, does anybody know how FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.erik.myapp") can fail for some users?

@finnschiermer
Copy link

^ @jpsim

@jpsim
Copy link
Contributor

jpsim commented Nov 22, 2016

This sounds like the file system operations you're performing might be prone to a race condition, if one process (e.g. main app) creates the Realm file after another process (e.g. Today extension) has checked to see if the file exists, but before the Realm can be moved by the second process (Today extension), then the Realm will be accessed while file system operations are being performed on it.

Are you sure you've ruled this scenario out? It would likely require some sort of interprocess mutex to ensure the race condition doesn't happen.

@fishfisher
Copy link
Author

Thanks for getting back to me. I haven't ruled this out. I will try to disable the realm in my today extension (as its usage is not as critical there as in the main app) so the file system operations are only executed in the main app. If the crash disappears we've found the reason.

@jpsim jpsim added S:Waiting For User T-Help and removed Blocked This issue is blocked by another issue S:On Hold T-Bug-Crash labels Nov 23, 2016
@TheHmmka
Copy link

"Can this be a cause for the issue? If so, does anybody know how FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.erik.myapp") can fail for some users?"
I am getting this error time to time... A only Apple knows why...

@rrrlasse
Copy link

We have found out that there might be problems if you access the same .realm file from two different apps/processes (multiple threads within the same app/process is fine though).

The apps/processes need to be running different versions for the error to occur: One needs to be Realm Cocoa 2.0.2 or older, and the other needs to be Realm Cocoa 2.0.3 or newer.

Is this the case?

@fishfisher
Copy link
Author

@rrrlasse Thanks for getting back to me. Both the main app and the extension targets the same pod in cocoapods, so I don't think they can be on different versions of Realm. However, this crash did start after going from RealmSwift 2.0.2 to 2.0.3.

@jpsim
Copy link
Contributor

jpsim commented Nov 29, 2016

@rrrlasse multiple processes on iOS/tvOS/watchOS accessing the same file will always be using the exact same version of Realm due to how those apps are allowed to be distributed. All bets are off for macOS and Android though.

@fishfisher I really still think the issue is the file system operations you're performing being racy. It's quite possible that changes between Realm Swift 2.0.2 and 2.0.3 made this race more likely to occur, but that the race was always there in the first place.

@jpsim
Copy link
Contributor

jpsim commented Dec 5, 2016

@fishfisher have you made any progress on this? Thanks!

@fishfisher
Copy link
Author

@jpsim Thanks for checking back. I'll be releasing a new version soon with Realm 2.1.1 and a quick fix for the possible race condition during initial realm access. TestFlight builds are looking good!

@jpsim
Copy link
Contributor

jpsim commented Dec 6, 2016

Great. I'll be closing this until we hear back from you then.

@jpsim jpsim closed this as completed Dec 6, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants