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

Crash when upserting User's `customData` #6010

Closed ahoang closed 2 years ago

ahoang commented 2 years ago

SDK and version

SDK : RealmSwift Version: 10.28.5

Observations

Crash log / stacktrace

0   Realm                               0x00000001079078cc _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x0000000107907814 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   Realm                               0x0000000107aac084 _ZN5realm4util14UniqueFunctionIFvONSt3__18optionalINS_4bson4BsonEEENS3_INS_3app8AppErrorEEEEE12SpecificImplIZNS8_12_GLOBAL__N_118get_update_handlerEONS1_IFvONS8_15MongoCollection12UpdateResultESA_EEEE3$_1E4callES7_OSA_ + 724
3   Realm                               0x0000000107a96d24 _ZN5realm4util14UniqueFunctionIFvRKNS_3app8ResponseEEE12SpecificImplIZNS2_3App13call_functionERKNSt3__110shared_ptrINS_8SyncUserEEERKNSA_12basic_stringIcNSA_11char_traitsIcEENSA_9allocatorIcEEEERKNSA_6vectorINS_4bson4BsonENSJ_ISQ_EEEERKNSA_8optionalISL_EEONS1_IFvONSV_ISQ_EENSV_INS2_8AppErrorEEEEEEE4$_12E4callES5_ + 392
4   Realm                               0x0000000107a963e0 _ZN5realm4util14UniqueFunctionIFvRKNS_3app8ResponseEEE12SpecificImplIZNS2_3App24do_authenticated_requestEONS2_7RequestERKNSt3__110shared_ptrINS_8SyncUserEEEOS7_E3$_9E4callES5_ + 108
5   Realm                               0x0000000107653f10 ___ZN12_GLOBAL__N_121CocoaNetworkTransport22send_request_to_serverEON5realm3app7RequestEONS1_4util14UniqueFunctionIFvRKNS2_8ResponseEEEE_block_invoke + 388
6   Realm                               0x000000010768d8f4 -[RLMSessionDelegate URLSession:task:didCompleteWithError:] + 292
7   CFNetwork                           0x000000018fd54968 CFURLRequestCopyHTTPRequestMethod + 2264
8   libdispatch.dylib                   0x0000000106f7c598 _dispatch_call_block_and_release + 32
9   libdispatch.dylib                   0x0000000106f7e04c _dispatch_client_callout + 20
10  libdispatch.dylib                   0x0000000106f860fc _dispatch_lane_serial_drain + 988
11  libdispatch.dylib                   0x0000000106f86e58 _dispatch_lane_invoke + 472
12  libdispatch.dylib                   0x0000000106f93cac _dispatch_workloop_worker_thread + 740
13  libsystem_pthread.dylib             0x00000001db4e8df8 _pthread_wqthread + 288
14  libsystem_pthread.dylib             0x00000001db4e8b98 start_wqthread + 8!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2022-11-09 20:48:46.757166-0800 Unscene[20178:31262701] /Users/realm/workspace/realm_realm-core_release_12.5.0/src/realm/object-store/util/bson/bson.hpp:177: [realm-core-12.5.0] Assertion failed: m_type == Bson::Type::ObjectId
0   Realm                               0x00000001079078cc _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x0000000107907814 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   Realm                               0x0000000107aac084 _ZN5realm4util14UniqueFunctionIFvONSt3__18optionalINS_4bson4BsonEEENS3_INS_3app8AppErrorEEEEE12SpecificImplIZNS8_12_GLOBAL__N_118get_update_handlerEONS1_IFvONS8_15MongoCollection12UpdateResultESA_EEEE3$_1E4callES7_OSA_ + 724
3   Realm                               0x0000000107a96d24 _ZN5realm4util14UniqueFunctionIFvRKNS_3app8ResponseEEE12SpecificImplIZNS2_3App13call_functionERKNSt3__110shared_ptrINS_8SyncUserEEERKNSA_12basic_stringIcNSA_11char_traitsIcEENSA_9allocatorIcEEEERKNSA_6vectorINS_4bson4BsonENSJ_ISQ_EEEERKNSA_8optionalISL_EEONS1_IFvONSV_ISQ_EENSV_INS2_8AppErrorEEEEEEE4$_12E4callES5_ + 392
4   Realm                               0x0000000107a963e0 _ZN5realm4util14UniqueFunctionIFvRKNS_3app8ResponseEEE12SpecificImplIZNS2_3App24do_authenticated_requestEONS2_7RequestERKNSt3__110shared_ptrINS_8SyncUserEEEOS7_E3$_9E4callES5_ + 108
5   Realm                               0x0000000107653f10 ___ZN12_GLOBAL__N_121CocoaNetworkTransport22send_request_to_serverEON5realm3app7RequestEONS1_4util14UniqueFunctionIFvRKNS2_8ResponseEEEE_block_invoke + 388
6   Realm                               0x000000010768d8f4 -[RLMSessionDelegate URLSession:task:didCompleteWithError:] + 292
7   CFNetwork                           0x000000018fd54968 CFURLRequestCopyHTTPRequestMethod + 2264
8   libdispatch.dylib                   0x0000000106f7c598 _dispatch_call_block_and_release + 32
9   libdispatch.dylib                   0x0000000106f7e04c _dispatch_client_callout + 20
10  libdispatch.dylib                   0x0000000106f860fc _dispatch_lane_serial_drain + 988
11  libdispatch.dylib                   0x0000000106f86e58 _dispatch_lane_invoke + 472
12  libdispatch.dylib                   0x0000000106f93cac _dispatch_workloop_worker_thread + 740
13  libsystem_pthread.dylib             0x00000001db4e8df8 _pthread_wqthread + 288
14  libsystem_pthread.dylib             0x00000001db4e8b98 start_wqthread + 8!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
(lldb) 

Steps & Code to Reproduce

  1. Try to upsert a user's customData by calling updateOneDocument
  2. The data has a primary key _id of ObjectId
  3. If I try to set it as an AnyBSON of ObjectId, it will return as an error, saying unable to insert
  4. If I try to set it as an AnyBSON of String it will successfully insert but then crash.
  5. If I change the _id type to String, and set the AnyBSON to string in the document, it will also write successfully, but crash afterward.
  6. This will only happen if it's an Insert, if the document already exists then it will not crash.
  7. If it is an insert, I can see the new document in the database, so the crash happens after the insert.
ironage commented 2 years ago

HI @ahoang, thanks for reporting this. I think this one was recently fixed. See https://github.com/realm/realm-core/issues/5345. Can you try updating the Swift SDK to 10.31.0 or later?

ironage commented 2 years ago

I haven't heard back, so I will assume that this issue has been resolved. If this is not the case, feel free to reopen or create a new issue.