realm / realm-core

Core database component for the Realm Mobile Database SDKs
https://realm.io
Apache License 2.0
1.02k stars 165 forks source link

RealmSwift App Crashes After Bulk Delete Using MongoDB Compass #7997

Closed ScottThomasMiller closed 3 months ago

ScottThomasMiller commented 3 months ago

SDK and version

SDK : RealmSwift (Cocoa, Java, etc) Version: 10.52.0

The Xcode error message is: Thread 11: "The following changes cannot be made in additive-only schema mode:\n- Property 'Post.title' has been made optional.\nIf your app is running in development mode, you can delete the realm and restart the app to update your schema."

Observations

Crash log / stacktrace

Info: Realm sync client ([realm-core-14.10.1]) Info: Platform: iOS Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:34:02 PDT 2024; root:xnu-10063.122.3~3/RELEASE_ARM64_T8120 iPhone15,2 To view your data in Atlas, go to this link: https://cloud.mongodb.com/links/651b55381a71d124d96f7cde/explorer/Cluster0/database/collection/find Info: Connection[1] Session[1]: Binding '/var/mobile/Containers/Data/Application/FA60AFDB-684A-4B6A-8B38-52966C4F559B/Documents/mongodb-realm/share-zjugltx/66b01b36bafe5e49f7128acc/flx_sync_default.realm' to '' Info: Connection[1] Session[1]: client_reset_config = false, Realm exists = true Info: Connection[1] Connecting to 'wss://us-east-1.aws.ws.services.cloud.mongodb.com:443/api/client/v2.0/app/share-zjugltx/realm-sync' Info: Connected to endpoint '34.202.24.183:443' (from '192.168.1.29:50121') Info: Connection[1] Connected to app services with request id: "66cc7e3bed13363877a835a0" /Users/scottmiller/Library/Developer/Xcode/DerivedData/Share-cxswqmcfiwkmxkahspymnznoxdiu/SourcePackages/checkouts/realm-core/src/realm/exceptions.cpp:80: [realm-core-14.10.1] Unreachable code 0 RealmSwift 0x00000001052c2504 _ZN5realm4utilL18terminate_internalERNSt3118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28 1 RealmSwift 0x00000001052c24e4 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 308 2 RealmSwift 0x00000001052c23b0 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0 3 RealmSwift 0x0000000104b67f04 _ZN5realm19exception_to_statusEv + 304 4 RealmSwift 0x0000000104e56fd4 _ZN5realm13AsyncOpenTask30wait_for_bootstrap_or_completeEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEENS_6StatusE + 596 5 RealmSwift 0x0000000104e5790c _ZN5realm13AsyncOpenTask26migrate_schema_or_completeEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3110shared_ptrINS_5_impl16RealmCoordinatorEEE + 224 6 RealmSwift 0x0000000104e59da0 _ZZN5realm13AsyncOpenTask5startENS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEEEN3$_0clENS_6StatusE + 380 7 RealmSwift 0x0000000104e59adc _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_13AsyncOpenTask5startENS1_IFvNS_19ThreadSafeReferenceESt13exception_ptrEEEE3$0E4callEOS2 + 60 8 RealmSwift 0x0000000104e8fd68 _ZNK5realm4util14UniqueFunctionIFvNS6StatusEEEclES2 + 112 9 RealmSwift 0x0000000104eb3f74 _ZZN5realm11SyncSession23add_completion_callbackENS_4util14UniqueFunctionIFvNS_6StatusEEEENS_5_impl20SyncProgressNotifier12NotifierTypeEENK4$12clES3 + 224 10 RealmSwift 0x0000000104eb3dd4 _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_11SyncSession23add_completion_callbackES4_NS_5_impl20SyncProgressNotifier12NotifierTypeEE4$12E4callEOS2 + 60 11 RealmSwift 0x0000000104e8fd68 _ZNK5realm4util14UniqueFunctionIFvNS6StatusEEEclES2 + 112 12 RealmSwift 0x0000000105059d18 _ZN5realm4sync14SessionWrapper22on_download_completionEv + 112 13 RealmSwift 0x0000000105059c98 _ZN5realm4sync10ClientImpl7Session22on_download_completionEv + 56 14 RealmSwift 0x000000010513dd8c _ZN5realm4sync10ClientImpl7Session29check_for_download_completionEv + 304 15 RealmSwift 0x000000010513b860 _ZN5realm4sync10ClientImpl7Session20receive_mark_messageEy + 416 16 RealmSwift 0x000000010513b644 _ZN5realm4sync10ClientImpl10Connection20receive_mark_messageEyy + 124 17 RealmSwift 0x0000000105138614 _ZN5realm5_impl14ClientProtocol22parse_message_receivedINS_4sync10ClientImpl10ConnectionEEEvRT_NSt3117basic_string_viewIcNS8_11char_traitsIcEEEE + 4388 18 RealmSwift 0x000000010513421c _ZN5realm4sync10ClientImpl10Connection23handle_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 112 19 RealmSwift 0x0000000105134104 _ZN5realm4sync10ClientImpl10Connection33websocket_binary_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 252 20 RealmSwift 0x000000010514f558 _ZN5realm4sync10ClientImpl10Connection21WebSocketObserverShim33websocket_binary_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 100 21 RealmSwift 0x00000001050b055c _ZN5realm4sync9websocket12_GLOBALN_120DefaultWebSocketImpl33websocket_binary_message_receivedEPKcm + 80 22 RealmSwift 0x00000001050e75d0 _ZN12_GLOBALN_19WebSocket17frame_reader_loopEv + 232 23 RealmSwift 0x00000001050e9094 _ZZN12_GLOBAL__N_19WebSocket17frame_reader_loopEvENKUlNSt3110error_codeEmE_clES2_m + 180 24 RealmSwift 0x00000001050e8fa8 _ZN5realm4util14UniqueFunctionIFvNSt3110error_codeEmEE12SpecificImplIZN12_GLOBALN_19WebSocket17frame_reader_loopEvEUlS3_mE_E4callEOS3_Om + 64 25 RealmSwift 0x00000001050c2df4 _ZNK5realm4util14UniqueFunctionIFvNSt3110error_codeEmEEclES3_m + 120 26 RealmSwift 0x00000001050c2b68 _ZN5realm4sync7network7Service9AsyncOper29do_recycle_and_execute_helperINS_4util14UniqueFunctionIFvNSt3110error_codeEmEEEJS8_mEEEvbRbTDpT0 + 108 27 RealmSwift 0x00000001050c2a80 _ZN5realm4sync7network7Service9AsyncOper22do_recycle_and_executeINS_4util14UniqueFunctionIFvNSt3110error_codeEmEEEJRS8_RmEEEvbRTDpOT0 + 168 28 RealmSwift 0x00000001050c24c4 _ZN5realm4sync7network7Service14BasicStreamOpsINS1_3ssl6StreamEE16BufferedReadOperINS_4util14UniqueFunctionIFvNSt3110error_codeEmEEEE19recycle_and_executeEv + 656 29 RealmSwift 0x00000001050d4134 _ZN5realm4sync7network7Service4Impl7executeERNSt3110unique_ptrINS2_9AsyncOperENS2_18LendersOperDeleterEEE + 36 30 RealmSwift 0x00000001050d3e40 _ZN5realm4sync7network7Service4Impl8run_implEb + 320 31 RealmSwift 0x00000001050cfc28 _ZN5realm4sync7network7Service4Impl17run_until_stoppedEv + 32 32 RealmSwift 0x00000001050cfbfc _ZN5realm4sync7network7Service17run_until_stoppedEv + 28 33 RealmSwift 0x00000001050a9a84 _ZN5realm4sync9websocket21DefaultSocketProvider10event_loopEv + 352 34 RealmSwift 0x00000001050ae1fc _ZNSt318invokeB8ue170006IMN5realm4sync9websocket21DefaultSocketProviderEFvvEPS4_JEvEEDTcldsdeclsr3stdE7declvalIT0_EEclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT1_EEEEOS9_OS8DpOSA + 116 35 RealmSwift 0x00000001050ae17c _ZNSt3116thread_executeB8ue170006INS_10unique_ptrINS_15thread_structENS_14default_deleteIS2_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEJPS9_EJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15tuple_indicesIJXspT2_EEEE + 48 36 RealmSwift 0x00000001050ade28 _ZNSt3114thread_proxyB8ue170006INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEPSAEEEEEPvSF + 84 37 libsystem_pthread.dylib 0x00000001ea20506c _pthread_start + 136 38 libsystem_pthread.dylib 0x00000001ea2000d8 thread_start + 8 /Users/scottmiller/Library/Developer/Xcode/DerivedData/Share-cxswqmcfiwkmxkahspymnznoxdiu/SourcePackages/checkouts/realm-core/src/realm/exceptions.cpp:80: [realm-core-14.10.1] Unreachable code 0 RealmSwift 0x00000001052c2504 _ZN5realm4utilL18terminate_internalERNSt3118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28 1 RealmSwift 0x00000001052c24e4 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 308 2 RealmSwift 0x00000001052c23b0 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0 3 RealmSwift 0x0000000104b67f04 _ZN5realm19exception_to_statusEv + 304 4 RealmSwift 0x0000000104e56fd4 _ZN5realm13AsyncOpenTask30wait_for_bootstrap_or_completeEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3110shared_ptrINS_5_impl16RealmCoordinatorEEENS_6StatusE + 596 5 RealmSwift 0x0000000104e5790c _ZN5realm13AsyncOpenTask26migrate_schema_or_completeEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3110shared_ptrINS_5_impl16RealmCoordinatorEEE + 224 6 RealmSwift 0x0000000104e59da0 _ZZN5realm13AsyncOpenTask5startENS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEEEN3$_0clENS_6StatusE + 380 7 RealmSwift 0x0000000104e59adc _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_13AsyncOpenTask5startENS1_IFvNS_19ThreadSafeReferenceESt13exception_ptrEEEE3$0E4callEOS2 + 60 8 RealmSwift 0x0000000104e8fd68 _ZNK5realm4util14UniqueFunctionIFvNS6StatusEEEclES2 + 112 9 RealmSwift 0x0000000104eb3f74 _ZZN5realm11SyncSession23add_completion_callbackENS_4util14UniqueFunctionIFvNS_6StatusEEEENS_5_impl20SyncProgressNotifier12NotifierTypeEENK4$12clES3 + 224 10 RealmSwift 0x0000000104eb3dd4 _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_11SyncSession23add_completion_callbackES4_NS_5_impl20SyncProgressNotifier12NotifierTypeEE4$12E4callEOS2 + 60 11 RealmSwift 0x0000000104e8fd68 _ZNK5realm4util14UniqueFunctionIFvNS6StatusEEEclES2 + 112 12 RealmSwift 0x0000000105059d18 _ZN5realm4sync14SessionWrapper22on_download_completionEv + 112 13 RealmSwift 0x0000000105059c98 _ZN5realm4sync10ClientImpl7Session22on_download_completionEv + 56 14 RealmSwift 0x000000010513dd8c _ZN5realm4sync10ClientImpl7Session29check_for_download_completionEv + 304 15 RealmSwift 0x000000010513b860 _ZN5realm4sync10ClientImpl7Session20receive_mark_messageEy + 416 16 RealmSwift 0x000000010513b644 _ZN5realm4sync10ClientImpl10Connection20receive_mark_messageEyy + 124 17 RealmSwift 0x0000000105138614 _ZN5realm5_impl14ClientProtocol22parse_message_receivedINS_4sync10ClientImpl10ConnectionEEEvRT_NSt3117basic_string_viewIcNS8_11char_traitsIcEEEE + 4388 18 RealmSwift 0x000000010513421c _ZN5realm4sync10ClientImpl10Connection23handle_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 112 19 RealmSwift 0x0000000105134104 _ZN5realm4sync10ClientImpl10Connection33websocket_binary_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 252 20 RealmSwift 0x000000010514f558 _ZN5realm4sync10ClientImpl10Connection21WebSocketObserverShim33websocket_binary_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 100 21 RealmSwift 0x00000001050b055c _ZN5realm4sync9websocket12_GLOBALN_120DefaultWebSocketImpl33websocket_binary_message_receivedEPKcm + 80 22 RealmSwift 0x00000001050e75d0 _ZN12_GLOBALN_19WebSocket17frame_reader_loopEv + 232 23 RealmSwift 0x00000001050e9094 _ZZN12_GLOBALN_19WebSocket17frame_reader_loopEvENKUlNSt3110error_codeEmE_clES2_m + 180 24 RealmSwift 0x00000001050e8fa8 _ZN5realm4util14UniqueFunctionIFvNSt3110error_codeEmEE12SpecificImplIZN12_GLOBALN_19WebSocket17frame_reader_loopEvEUlS3_mE_E4callEOS3_Om + 64 25 RealmSwift 0x00000001050c2df4 _ZNK5realm4util14UniqueFunctionIFvNSt3110error_codeEmEEclES3_m + 120 26 RealmSwift 0x00000001050c2b68 _ZN5realm4sync7network7Service9AsyncOper29do_recycle_and_execute_helperINS_4util14UniqueFunctionIFvNSt3110error_codeEmEEEJS8_mEEEvbRbTDpT0 + 108 27 RealmSwift 0x00000001050c2a80 _ZN5realm4sync7network7Service9AsyncOper22do_recycle_and_executeINS_4util14UniqueFunctionIFvNSt3110error_codeEmEEEJRS8_RmEEEvbRTDpOT0 + 168 28 RealmSwift 0x00000001050c24c4 _ZN5realm4sync7network7Service14BasicStreamOpsINS1_3ssl6StreamEE16BufferedReadOperINS_4util14UniqueFunctionIFvNSt3110error_codeEmEEEE19recycle_and_executeEv + 656 29 RealmSwift 0x00000001050d4134 _ZN5realm4sync7network7Service4Impl7executeERNSt3110unique_ptrINS2_9AsyncOperENS2_18LendersOperDeleterEEE + 36 30 RealmSwift 0x00000001050d3e40 _ZN5realm4sync7network7Service4Impl8run_implEb + 320 31 RealmSwift 0x00000001050cfc28 _ZN5realm4sync7network7Service4Impl17run_until_stoppedEv + 32 32 RealmSwift 0x00000001050cfbfc _ZN5realm4sync7network7Service17run_until_stoppedEv + 28 33 RealmSwift 0x00000001050a9a84 _ZN5realm4sync9websocket21DefaultSocketProvider10event_loopEv + 352 34 RealmSwift 0x00000001050ae1fc _ZNSt318invokeB8ue170006IMN5realm4sync9websocket21DefaultSocketProviderEFvvEPS4_JEvEEDTcldsdeclsr3stdE7declvalIT0_EEclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT1_EEEEOS9_OS8DpOSA + 116 35 RealmSwift 0x00000001050ae17c _ZNSt3116thread_executeB8ue170006INS_10unique_ptrINS_15thread_structENS_14default_deleteIS2_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEJPS9_EJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15tuple_indicesIJXspT2_EEEE + 48 36 RealmSwift 0x00000001050ade28 _ZNSt3114thread_proxyB8ue170006INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEPSAEEEEEPvSF + 84 37 libsystem_pthread.dylib 0x00000001ea20506c _pthread_start + 136 38 libsystem_pthread.dylib 0x00000001ea2000d8 thread_start + 8 !!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

Steps & Code to Reproduce

sync-by-unito[bot] commented 3 months ago

➤ PM Bot commented:

Jira ticket: RCORE-2240

ScottThomasMiller commented 3 months ago

I did a bulk delete of all records in the Post table, and then reran my app from Xcode, and then it crashed. It was running fine before the bulk delete.

nicola-cab commented 3 months ago

@michael-wb is this a failure in the websocket impl?

ScottThomasMiller commented 3 months ago

@michael-wb is this a failure in the websocket impl?

I'm not sure. It happens right away, upon startup.

nicola-cab commented 3 months ago
Status exception_to_status() noexcept
{
    try {
        throw;
    }
    catch (const Exception& e) {
        return e.to_status();
    }
    catch (const std::exception& e) {
        return Status(ErrorCodes::UnknownError,
                      util::format("Caught std::exception of type %1: %2", util::get_type_name(e), e.what()));
    }
    catch (...) {
        --> REALM_UNREACHABLE();   //seems to be crashing here. 
    }
}

It seems we are not handling the error somehow @michael-wb ?

michael-wb commented 3 months ago

Hi @ScottThomasMiller, It sounds like you deleted all the records outside your XCode app and now the app is receiving the following error when it tries to either use @AsyncOpen (or @AutoOpen) when opening the ream - is that correct?

The following changes cannot be made in additive-only schema mode:\n- Property 'Post.title' has been made optional.\nIf your app is running in development mode, you can delete the realm and restart the app to update your schema.

Did you happen to make any changes to the schema either locally or on the server as well? From this error message, it sounds like the local schema has an additive change compared to the server schema. You may need to delete the realm and start over to recover from this error.

michael-wb commented 3 months ago

@ScottThomasMiller - would you be able to provide a debug or trace log for when this crash occurs? Thank you!

ScottThomasMiller commented 3 months ago

Hi @ScottThomasMiller, It sounds like you deleted all the records outside your XCode app and now the app is receiving the following error when it tries to either use @AsyncOpen (or @AutoOpen) when opening the ream - is that correct?

The following changes cannot be made in additive-only schema mode:\n- Property 'Post.title' has been made optional.\nIf your app is running in development mode, you can delete the realm and restart the app to update your schema.

Did you happen to make any changes to the schema either locally or on the server as well? From this error message, it sounds like the local schema has an additive change compared to the server schema. You may need to delete the realm and start over to recover from this error.

That was the issue: I had made a change to the data model. Thanks for pointing it out. If I undo that one change, then the app no longer crashes.

michael-wb commented 3 months ago

Glad it's working now, @ScottThomasMiller. Are we good to close this issue?

ScottThomasMiller commented 3 months ago

Yes thanks. And thank you for your prompt assistance.