Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-1971

SEGV or TSAN race on migrate_schema_or_complete

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      It started to fail after #7239

      CI failure

      and it's either sigv under ASAN
      <details><summary>stacktrace</summary>

      AddressSanitizer:DEADLYSIGNAL
      =================================================================
      ==57295==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000108724c38 bp 0x00016ba82d20 sp 0x00016ba82d20 T43245)
      ==57295==The signal is caused by a READ memory access.
      ==57295==Hint: address points to the zero page.
          #0 0x108724c38 in realm::DB::get_version_of_latest_snapshot() db.cpp:2453
          #1 0x107efd868 in realm::_impl::RealmCoordinator::on_change() realm_coordinator.cpp:871
          #2 0x108075770 in realm::_impl::ExternalCommitHelper::listen() external_commit_helper.cpp:234
          #3 0x108075da4 in void* std::__1::__thread_proxy[abi:v160006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0>>(void*) thread:299
          #4 0x1842b6030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
          #5 0x1842b0e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)
      
      ==57295==Register values:
       x[0] = 0x0000000000000000   x[1] = 0x0000000000000000   x[2] = 0x0000000000000000   x[3] = 0x000000016ba82de0  
       x[4] = 0x0000000000000001   x[5] = 0x0000000000000000   x[6] = 0x000000016ba00000   x[7] = 0x0000000000000001  
       x[8] = 0x0000000000000370   x[9] = 0x0000007000020000  x[10] = 0x0000000000000000  x[11] = 0x0000000000000002  
      x[12] = 0x0000000000000000  x[13] = 0x0000000000000000  x[14] = 0x0000000000007e01  x[15] = 0x0000000000000006  
      x[16] = 0x000000000000016b  x[17] = 0x000000010b864750  x[18] = 0x0000000000000000  x[19] = 0x00000001289ae498  
      x[20] = 0x00000001289ae7b0  x[21] = 0x0000007000020000  x[22] = 0x0000000025135cf6  x[23] = 0x00000000f8f8f8f8  
      x[24] = 0x0000000133f1bfe8  x[25] = 0x000000016ba82de0  x[26] = 0x0000007000020000  x[27] = 0x00000000267e37fd  
      x[28] = 0x000000702d7705ac     fp = 0x000000016ba82d20     lr = 0x0000000107efd86c     sp = 0x000000016ba82d20  
      AddressSanitizer can not provide additional info.
      SUMMARY: AddressSanitizer: SEGV db.cpp:2453 in realm::DB::get_version_of_latest_snapshot()
      Thread T43245 created by T0 here:
          #0 0x10b80c1b0 in wrap_pthread_create+0x54 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x4c1b0)
          #1 0x108074038 in realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&) external_commit_helper.cpp:173
          #2 0x107ef88b0 in realm::_impl::RealmCoordinator::init_external_helpers() realm_coordinator.cpp:547
          #3 0x107ef1e74 in realm::_impl::RealmCoordinator::open_db() realm_coordinator.cpp:528
          #4 0x107ef8168 in realm::_impl::RealmCoordinator::get_synchronized_realm(realm::RealmConfig) realm_coordinator.cpp:422
          #5 0x107e7648c in realm::Realm::get_synchronized_realm(realm::RealmConfig) shared_realm.cpp:192
          #6 0x1077060f0 in realm::app::(anonymous namespace)::async_open_realm(realm::RealmConfig const&) flx_schema_migration.cpp:83
          #7 0x1076ee8dc in realm::app::CATCH2_INTERNAL_TEST_27() flx_schema_migration.cpp:915
          #8 0x107c930f8 in Catch::RunContext::runCurrentTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) catch_run_context.cpp:501
          #9 0x107c92060 in Catch::RunContext::runTest(Catch::TestCaseHandle const&) catch_run_context.cpp:232
          #10 0x107c22720 in Catch::(anonymous namespace)::TestGroup::execute() catch_session.cpp:110
          #11 0x107c20904 in Catch::Session::runInternal() catch_session.cpp:332
          #12 0x107c1fab8 in Catch::Session::run() catch_session.cpp:263
          #13 0x1066f3cec in run_object_store_tests(int, char const**) test_runner.cpp:96
          #14 0x183f350dc  (<unknown module>)
      
      ==57295==ABORTING
      <end of output>
      Test time = 827.51 sec
      ----------------------------------------------------------
      Test Failed.
      "ObjectStoreTests-baas" end time: Jan 26 14:14 CET
      "ObjectStoreTests-baas" time elapsed: 00:13:47
      ----------------------------------------------------------
      
      End testing: Jan 26 14:14 CET
      
      objstore-baas = 827.51 sec*proc
      
      objstore-local = 130.35 sec*proc
      

      </details>

      ..or a datarace under tsan:
      <details><summary>stacktrace</summary>

      Command: "/Users/user/r/core/.bot/test/object-store/realm-object-store-tests.app/Contents/MacOS/realm-object-store-tests" "[baas]"
      Directory: /Users/user/r/core/.bot/test/object-store
      "ObjectStoreTests-baas" start time: Jan 31 20:39 CET
      Output:
      ----------------------------------------------------------
      Filters: [baas]
      Randomness seeded to: 553406638
      Websocket redirect test: User logged out
      Websocket redirect test: User logged out
      ==================
      WARNING: ThreadSanitizer: data race (pid=39432)
        Write of size 8 at 0x00010cb0a258 by thread T39513 (mutexes: write M0, write M1):
          #0 realm::DB::close_internal(std::__1::unique_lock<realm::util::InterprocessMutex>, bool) db.cpp:1839 (realm-object-store-tests:arm64+0x101aafe04)
          #1 realm::DB::close(bool) db.cpp:1779 (realm-object-store-tests:arm64+0x101aad044)
          #2 realm::_impl::RealmCoordinator::close() realm_coordinator.cpp:560 (realm-object-store-tests:arm64+0x1016f87dc)
          #3 auto realm::util::future_details::call<realm::AsyncOpenTask::migrate_schema_or_complete(realm::util::UniqueFunction<void (realm::ThreadSafeReference, std::exception_ptr)>&&, std::__1::shared_ptr<realm::_impl::RealmCoordinator>, realm::Status)::$_1::operator()(realm::Status)::'lambda'(realm::Status)&>(realm::AsyncOpenTask::migrate_schema_or_complete(realm::util::UniqueFunction<void (realm::ThreadSafeReference, std::exception_ptr)>&&, std::__1::shared_ptr<realm::_impl::RealmCoordinator>, realm::Status)::$_1::operator()(realm::Status)::'lambda'(realm::Status)&, realm::StatusWith<realm::util::future_details::FakeVoid>) future.hpp:123 (realm-object-store-tests:arm64+0x101739f50)
          #4 realm::util::UniqueFunction<void (realm::util::future_details::SharedStateBase*)>::SpecificImpl<void realm::util::future_details::Future<realm::util::future_details::FakeVoid>::get_async<realm::AsyncOpenTask::migrate_schema_or_complete(realm::util::UniqueFunction<void (realm::ThreadSafeReference, std::exception_ptr)>&&, std::__1::shared_ptr<realm::_impl::RealmCoordinator>, realm::Status)::$_1::operator()(realm::Status)::'lambda'(realm::Status)>(realm::AsyncOpenTask::migrate_schema_or_complete(realm::util::UniqueFunction<void (realm::ThreadSafeReference, std::exception_ptr)>&&, std::__1::shared_ptr<realm::_impl::RealmCoordinator>, realm::Status)::$_1::operator()(realm::Status)::'lambda'(realm::Status)&&) &&::'lambda'()::operator()() const::'lambda'(realm::util::future_details::SharedStateBase*)>::call(realm::util::future_details::SharedStateBase*&&) functional.hpp:154 (realm-object-store-tests:arm64+0x10173a68c)
          #5 void realm::util::future_details::Promise<void>::set_impl<void realm::util::future_details::Promise<void>::emplace_value<>()::'lambda'()>(void realm::util::future_details::Promise<void>::emplace_value<>()::'lambda'()&&) future.hpp:550 (realm-object-store-tests:arm64+0x101138320)
          #6 realm::util::UniqueFunction<void (realm::Status)>::SpecificImpl<realm::sync::ClientImpl::notify_session_terminated()::$_3>::call(realm::Status&&) functional.hpp:154 (realm-object-store-tests:arm64+0x1019087d0)
          #7 realm::util::UniqueFunction<void (realm::Status)>::SpecificImpl<realm::sync::ClientImpl::post(realm::util::UniqueFunction<void (realm::Status)>&&)::$_1>::call(realm::Status&&) functional.hpp:154 (realm-object-store-tests:arm64+0x1018be598)
          #8 realm::sync::network::Service::PostOper<realm::util::UniqueFunction<void (realm::Status)>>::recycle_and_execute() network.hpp:2015 (realm-object-store-tests:arm64+0x1010652a8)
          #9 realm::sync::network::Service::Impl::run_impl(bool) network.cpp:1574 (realm-object-store-tests:arm64+0x10196d54c)
          #10 realm::sync::network::Service::run_until_stopped() network.cpp:1776 (realm-object-store-tests:arm64+0x101969aec)
          #11 realm::sync::websocket::DefaultSocketProvider::event_loop() default_socket.cpp:619 (realm-object-store-tests:arm64+0x10195ae90)
          #12 void* std::__1::__thread_proxy[abi:v160006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (realm::sync::websocket::DefaultSocketProvider::*)(), realm::sync::websocket::DefaultSocketProvider*>>(void*) thread:299 (realm-object-store-tests:arm64+0x10195c670)
      
        Previous read of size 8 at 0x00010cb0a258 by thread T39543:
          #0 realm::DB::get_version_of_latest_snapshot() db.cpp:2453 (realm-object-store-tests:arm64+0x101ab103c)
          #1 realm::_impl::RealmCoordinator::on_change() realm_coordinator.cpp:871 (realm-object-store-tests:arm64+0x1016faffc)
          #2 realm::_impl::ExternalCommitHelper::listen() external_commit_helper.cpp:234 (realm-object-store-tests:arm64+0x10179dc5c)
          #3 void* std::__1::__thread_proxy[abi:v160006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0>>(void*) thread:299 (realm-object-store-tests:arm64+0x10179de50)
      
        Location is heap block of size 1256 at 0x00010cb0a000 allocated by main thread:
          #0 operator new(unsigned long) <null>:131042948 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x84420)
          #1 std::__1::shared_ptr<realm::DB> std::__1::allocate_shared[abi:v160006]<realm::DB, std::__1::allocator<realm::DB>, realm::DB::Private, realm::DBOptions const&, void>(std::__1::allocator<realm::DB> const&, realm::DB::Private&&, realm::DBOptions const&) shared_ptr.h:994 (realm-object-store-tests:arm64+0x101aba4a8)
          #2 realm::DB::create(std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, realm::DBOptions const&) db.cpp:2763 (realm-object-store-tests:arm64+0x101ab4868)
          #3 realm::_impl::RealmCoordinator::open_db() realm_coordinator.cpp:491 (realm-object-store-tests:arm64+0x1016f57d8)
          #4 realm::_impl::RealmCoordinator::get_synchronized_realm(realm::RealmConfig) realm_coordinator.cpp:422 (realm-object-store-tests:arm64+0x1016f8258)
          #5 realm::Realm::get_synchronized_realm(realm::RealmConfig) shared_realm.cpp:192 (realm-object-store-tests:arm64+0x1016b6e48)
          #6 realm::app::(anonymous namespace)::async_open_realm(realm::RealmConfig const&) flx_schema_migration.cpp:83 (realm-object-store-tests:arm64+0x1013a4900)
          #7 realm::app::CATCH2_INTERNAL_TEST_19() flx_schema_migration.cpp:562 (realm-object-store-tests:arm64+0x101393a84)
          #8 Catch::TestInvokerAsFunction::invoke() const catch_test_case_registry_impl.cpp:149 (realm-object-store-tests:arm64+0x1015e4880)
          #9 Catch::RunContext::runCurrentTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) catch_run_context.cpp:501 (realm-object-store-tests:arm64+0x1015db724)
          #10 Catch::RunContext::runTest(Catch::TestCaseHandle const&) catch_run_context.cpp:232 (realm-object-store-tests:arm64+0x1015db044)
          #11 Catch::(anonymous namespace)::TestGroup::execute() catch_session.cpp:110 (realm-object-store-tests:arm64+0x1015a4fc4)
          #12 Catch::Session::runInternal() catch_session.cpp:332 (realm-object-store-tests:arm64+0x1015a4260)
          #13 Catch::Session::run() catch_session.cpp:263 (realm-object-store-tests:arm64+0x1015a39f8)
          #14 run_object_store_tests(int, char const**) test_runner.cpp:96 (realm-object-store-tests:arm64+0x100d33d60)
          #15 main main.cpp:24 (realm-object-store-tests:arm64+0x101579c90)
      
        Mutex M0 (0x00010c40a8d0) created at:
          #0 pthread_mutex_lock <null>:131042948 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x3cf8c)
          #1 std::__1::mutex::lock() <null>:131042948 (libc++.1.dylib:arm64e+0x162fc)
          #2 realm::app::(anonymous namespace)::async_open_realm(realm::RealmConfig const&) flx_schema_migration.cpp:88 (realm-object-store-tests:arm64+0x1013a4a54)
          #3 realm::app::CATCH2_INTERNAL_TEST_19() flx_schema_migration.cpp:562 (realm-object-store-tests:arm64+0x101393a84)
          #4 Catch::TestInvokerAsFunction::invoke() const catch_test_case_registry_impl.cpp:149 (realm-object-store-tests:arm64+0x1015e4880)
          #5 Catch::RunContext::runCurrentTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) catch_run_context.cpp:501 (realm-object-store-tests:arm64+0x1015db724)
          #6 Catch::RunContext::runTest(Catch::TestCaseHandle const&) catch_run_context.cpp:232 (realm-object-store-tests:arm64+0x1015db044)
          #7 Catch::(anonymous namespace)::TestGroup::execute() catch_session.cpp:110 (realm-object-store-tests:arm64+0x1015a4fc4)
          #8 Catch::Session::runInternal() catch_session.cpp:332 (realm-object-store-tests:arm64+0x1015a4260)
          #9 Catch::Session::run() catch_session.cpp:263 (realm-object-store-tests:arm64+0x1015a39f8)
          #10 run_object_store_tests(int, char const**) test_runner.cpp:96 (realm-object-store-tests:arm64+0x100d33d60)
          #11 main main.cpp:24 (realm-object-store-tests:arm64+0x101579c90)
      
        Mutex M1 (0x00010cb0a028) created at:
          #0 pthread_mutex_lock <null>:131042948 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x3cf8c)
          #1 std::__1::mutex::lock() <null>:131042948 (libc++.1.dylib:arm64e+0x162fc)
          #2 realm::DB::start_read(realm::VersionID) db.cpp:2622 (realm-object-store-tests:arm64+0x101aaca78)
          #3 realm::sync::MigrationStore::load_data(bool) migration_store.cpp:55 (realm-object-store-tests:arm64+0x1018de5f8)
          #4 realm::sync::MigrationStore::MigrationStore(realm::sync::MigrationStore::Private, std::__1::shared_ptr<realm::DB>) migration_store.cpp:30 (realm-object-store-tests:arm64+0x1018de148)
          #5 std::__1::__shared_ptr_emplace<realm::sync::MigrationStore, std::__1::allocator<realm::sync::MigrationStore>>::__shared_ptr_emplace[abi:v160006]<realm::sync::MigrationStore::Private, std::__1::shared_ptr<realm::DB>>(std::__1::allocator<realm::sync::MigrationStore>, realm::sync::MigrationStore::Private&&, std::__1::shared_ptr<realm::DB>&&) shared_ptr.h:276 (realm-object-store-tests:arm64+0x1018e1848)
          #6 std::__1::shared_ptr<realm::sync::MigrationStore> std::__1::allocate_shared[abi:v160006]<realm::sync::MigrationStore, std::__1::allocator<realm::sync::MigrationStore>, realm::sync::MigrationStore::Private, std::__1::shared_ptr<realm::DB>, void>(std::__1::allocator<realm::sync::MigrationStore> const&, realm::sync::MigrationStore::Private&&, std::__1::shared_ptr<realm::DB>&&) shared_ptr.h:995 (realm-object-store-tests:arm64+0x1018e1688)
          #7 realm::sync::MigrationStore::create(std::__1::shared_ptr<realm::DB>) migration_store.cpp:23 (realm-object-store-tests:arm64+0x1018ddfc8)
          #8 realm::SyncSession::SyncSession(realm::SyncSession::Private, realm::_impl::SyncClient&, std::__1::shared_ptr<realm::DB>, realm::RealmConfig const&, realm::SyncManager*) sync_session.cpp:395 (realm-object-store-tests:arm64+0x10174acc8)
          #9 realm::SyncSession::SyncSession(realm::SyncSession::Private, realm::_impl::SyncClient&, std::__1::shared_ptr<realm::DB>, realm::RealmConfig const&, realm::SyncManager*) sync_session.cpp:399 (realm-object-store-tests:arm64+0x10174b958)
          #10 std::__1::__shared_ptr_emplace<realm::SyncSession, std::__1::allocator<realm::SyncSession>>::__shared_ptr_emplace[abi:v160006]<realm::SyncSession::Private, realm::_impl::SyncClient&, std::__1::shared_ptr<realm::DB>, realm::RealmConfig const&, realm::SyncManager*>(std::__1::allocator<realm::SyncSession>, realm::SyncSession::Private&&, realm::_impl::SyncClient&, std::__1::shared_ptr<realm::DB>&&, realm::RealmConfig const&, realm::SyncManager*&&) shared_ptr.h:276 (realm-object-store-tests:arm64+0x1017424c0)
          #11 std::__1::shared_ptr<realm::SyncSession> std::__1::allocate_shared[abi:v160006]<realm::SyncSession, std::__1::allocator<realm::SyncSession>, realm::SyncSession::Private, realm::_impl::SyncClient&, std::__1::shared_ptr<realm::DB>, realm::RealmConfig const&, realm::SyncManager*, void>(std::__1::allocator<realm::SyncSession> const&, realm::SyncSession::Private&&, realm::_impl::SyncClient&, std::__1::shared_ptr<realm::DB>&&, realm::RealmConfig const&, realm::SyncManager*&&) shared_ptr.h:995 (realm-object-store-tests:arm64+0x1017422c8)
          #12 realm::SyncManager::get_session(std::__1::shared_ptr<realm::DB>, realm::RealmConfig const&) sync_manager.cpp:651 (realm-object-store-tests:arm64+0x101741318)
          #13 realm::_impl::RealmCoordinator::init_external_helpers() realm_coordinator.cpp:542 (realm-object-store-tests:arm64+0x1016f8504)
          #14 realm::_impl::RealmCoordinator::open_db() realm_coordinator.cpp:528 (realm-object-store-tests:arm64+0x1016f5c50)
          #15 realm::_impl::RealmCoordinator::get_synchronized_realm(realm::RealmConfig) realm_coordinator.cpp:422 (realm-object-store-tests:arm64+0x1016f8258)
          #16 realm::Realm::get_synchronized_realm(realm::RealmConfig) shared_realm.cpp:192 (realm-object-store-tests:arm64+0x1016b6e48)
          #17 realm::app::(anonymous namespace)::async_open_realm(realm::RealmConfig const&) flx_schema_migration.cpp:83 (realm-object-store-tests:arm64+0x1013a4900)
          #18 realm::app::CATCH2_INTERNAL_TEST_19() flx_schema_migration.cpp:562 (realm-object-store-tests:arm64+0x101393a84)
          #19 Catch::TestInvokerAsFunction::invoke() const catch_test_case_registry_impl.cpp:149 (realm-object-store-tests:arm64+0x1015e4880)
          #20 Catch::RunContext::runCurrentTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) catch_run_context.cpp:501 (realm-object-store-tests:arm64+0x1015db724)
          #21 Catch::RunContext::runTest(Catch::TestCaseHandle const&) catch_run_context.cpp:232 (realm-object-store-tests:arm64+0x1015db044)
          #22 Catch::(anonymous namespace)::TestGroup::execute() catch_session.cpp:110 (realm-object-store-tests:arm64+0x1015a4fc4)
          #23 Catch::Session::runInternal() catch_session.cpp:332 (realm-object-store-tests:arm64+0x1015a4260)
          #24 Catch::Session::run() catch_session.cpp:263 (realm-object-store-tests:arm64+0x1015a39f8)
          #25 run_object_store_tests(int, char const**) test_runner.cpp:96 (realm-object-store-tests:arm64+0x100d33d60)
          #26 main main.cpp:24 (realm-object-store-tests:arm64+0x101579c90)
      
        Thread T39513 (tid=1868274, running) created by main thread at:
          #0 pthread_create <null>:131042948 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x3062c)
          #1 std::__1::thread::thread<void (realm::sync::websocket::DefaultSocketProvider::*)(), realm::sync::websocket::DefaultSocketProvider*, void>(void (realm::sync::websocket::DefaultSocketProvider::*&&)(), realm::sync::websocket::DefaultSocketProvider*&&) thread:315 (realm-object-store-tests:arm64+0x10195c55c)
          #2 realm::sync::websocket::DefaultSocketProvider::start() default_socket.cpp:544 (realm-object-store-tests:arm64+0x10195a988)
          #3 realm::sync::websocket::DefaultSocketProvider::DefaultSocketProvider(std::__1::shared_ptr<realm::util::Logger> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::shared_ptr<realm::BindingCallbackThreadObserver> const&, realm::util::TaggedBool<realm::sync::websocket::DefaultSocketProvider::AutoStartTag>) default_socket.cpp:515 (realm-object-store-tests:arm64+0x10195a7e8)
          #4 realm::sync::websocket::DefaultSocketProvider::DefaultSocketProvider(std::__1::shared_ptr<realm::util::Logger> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::shared_ptr<realm::BindingCallbackThreadObserver> const&, realm::util::TaggedBool<realm::sync::websocket::DefaultSocketProvider::AutoStartTag>) default_socket.cpp:511 (realm-object-store-tests:arm64+0x10195aaa4)
          #5 std::__1::shared_ptr<realm::sync::websocket::DefaultSocketProvider> std::__1::allocate_shared[abi:v160006]<realm::sync::websocket::DefaultSocketProvider, std::__1::allocator<realm::sync::websocket::DefaultSocketProvider>, std::__1::shared_ptr<realm::util::Logger> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::shared_ptr<realm::BindingCallbackThreadObserver> const&, void>(std::__1::allocator<realm::sync::websocket::DefaultSocketProvider> const&, std::__1::shared_ptr<realm::util::Logger> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&&, std::__1::shared_ptr<realm::BindingCallbackThreadObserver> const&) shared_ptr.h:995 (realm-object-store-tests:arm64+0x10174683c)
          #6 realm::_impl::SyncClient::SyncClient(std::__1::shared_ptr<realm::util::Logger> const&, realm::SyncClientConfig const&, std::__1::weak_ptr<realm::SyncManager const>)::'lambda'()::operator()() const sync_client.hpp:55 (realm-object-store-tests:arm64+0x101745f14)
          #7 realm::_impl::SyncClient::SyncClient(std::__1::shared_ptr<realm::util::Logger> const&, realm::SyncClientConfig const&, std::__1::weak_ptr<realm::SyncManager const>) sync_client.hpp:46 (realm-object-store-tests:arm64+0x101745884)
          #8 realm::SyncManager::create_sync_client() const sync_manager.cpp:749 (realm-object-store-tests:arm64+0x101741b84)
          #9 realm::SyncManager::get_sync_client() const sync_manager.cpp:743 (realm-object-store-tests:arm64+0x101741618)
          #10 TestAppSession::TestAppSession(realm::AppSession, std::__1::shared_ptr<realm::app::GenericNetworkTransport>, realm::util::TaggedBool<DeleteAppTag>, realm::ReconnectMode, std::__1::shared_ptr<realm::sync::SyncSocketProvider>) test_file.cpp:360 (realm-object-store-tests:arm64+0x100f31d58)
          #11 TestAppSession::TestAppSession(realm::AppSession, std::__1::shared_ptr<realm::app::GenericNetworkTransport>, realm::util::TaggedBool<DeleteAppTag>, realm::ReconnectMode, std::__1::shared_ptr<realm::sync::SyncSocketProvider>) test_file.cpp:339 (realm-object-store-tests:arm64+0x100f32234)
          #12 realm::app::FLXSyncTestHarness::FLXSyncTestHarness(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, realm::app::FLXSyncTestHarness::ServerSchema, std::__1::shared_ptr<realm::app::GenericNetworkTransport>, std::__1::shared_ptr<realm::sync::SyncSocketProvider>) flx_sync_harness.hpp:95 (realm-object-store-tests:arm64+0x100f1c47c)
          #13 realm::app::CATCH2_INTERNAL_TEST_19() flx_schema_migration.cpp:485 (realm-object-store-tests:arm64+0x101391434)
          #14 Catch::TestInvokerAsFunction::invoke() const catch_test_case_registry_impl.cpp:149 (realm-object-store-tests:arm64+0x1015e4880)
          #15 Catch::RunContext::runCurrentTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) catch_run_context.cpp:501 (realm-object-store-tests:arm64+0x1015db724)
          #16 Catch::RunContext::runTest(Catch::TestCaseHandle const&) catch_run_context.cpp:232 (realm-object-store-tests:arm64+0x1015db044)
          #17 Catch::(anonymous namespace)::TestGroup::execute() catch_session.cpp:110 (realm-object-store-tests:arm64+0x1015a4fc4)
          #18 Catch::Session::runInternal() catch_session.cpp:332 (realm-object-store-tests:arm64+0x1015a4260)
          #19 Catch::Session::run() catch_session.cpp:263 (realm-object-store-tests:arm64+0x1015a39f8)
          #20 run_object_store_tests(int, char const**) test_runner.cpp:96 (realm-object-store-tests:arm64+0x100d33d60)
          #21 main main.cpp:24 (realm-object-store-tests:arm64+0x101579c90)
      
        Thread T39543 (tid=1868756, running) created by main thread at:
          #0 pthread_create <null>:131042948 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x3062c)
          #1 realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&) external_commit_helper.cpp:173 (realm-object-store-tests:arm64+0x10179d4b8)
          #2 realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&) external_commit_helper.cpp:94 (realm-object-store-tests:arm64+0x10179d8ec)
          #3 realm::_impl::RealmCoordinator::init_external_helpers() realm_coordinator.cpp:547 (realm-object-store-tests:arm64+0x1016f8440)
          #4 realm::_impl::RealmCoordinator::open_db() realm_coordinator.cpp:528 (realm-object-store-tests:arm64+0x1016f5c50)
          #5 realm::_impl::RealmCoordinator::get_synchronized_realm(realm::RealmConfig) realm_coordinator.cpp:422 (realm-object-store-tests:arm64+0x1016f8258)
          #6 realm::Realm::get_synchronized_realm(realm::RealmConfig) shared_realm.cpp:192 (realm-object-store-tests:arm64+0x1016b6e48)
          #7 realm::app::(anonymous namespace)::async_open_realm(realm::RealmConfig const&) flx_schema_migration.cpp:83 (realm-object-store-tests:arm64+0x1013a4900)
          #8 realm::app::CATCH2_INTERNAL_TEST_19() flx_schema_migration.cpp:562 (realm-object-store-tests:arm64+0x101393a84)
          #9 Catch::TestInvokerAsFunction::invoke() const catch_test_case_registry_impl.cpp:149 (realm-object-store-tests:arm64+0x1015e4880)
          #10 Catch::RunContext::runCurrentTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) catch_run_context.cpp:501 (realm-object-store-tests:arm64+0x1015db724)
          #11 Catch::RunContext::runTest(Catch::TestCaseHandle const&) catch_run_context.cpp:232 (realm-object-store-tests:arm64+0x1015db044)
          #12 Catch::(anonymous namespace)::TestGroup::execute() catch_session.cpp:110 (realm-object-store-tests:arm64+0x1015a4fc4)
          #13 Catch::Session::runInternal() catch_session.cpp:332 (realm-object-store-tests:arm64+0x1015a4260)
          #14 Catch::Session::run() catch_session.cpp:263 (realm-object-store-tests:arm64+0x1015a39f8)
          #15 run_object_store_tests(int, char const**) test_runner.cpp:96 (realm-object-store-tests:arm64+0x100d33d60)
          #16 main main.cpp:24 (realm-object-store-tests:arm64+0x101579c90)
      
      SUMMARY: ThreadSanitizer: data race db.cpp:1839 in realm::DB::close_internal(std::__1::unique_lock<realm::util::InterprocessMutex>, bool)
      ==================
      

      </details>

      access to db here in RealmCoordinator::on_change is unguarded so it leads to a race after 'close' and the call from external commit listener

            Assignee:
            daniel.tabacaru@mongodb.com Daniel Tabacaru
            Reporter:
            kirill.burtsev@mongodb.com Kirill Burtsev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: