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

Data race involving SharedGroup and encrypted file mappings #3267

Closed
finnschiermer opened this issue Mar 26, 2019 · 1 comment
Closed

Data race involving SharedGroup and encrypted file mappings #3267

finnschiermer opened this issue Mar 26, 2019 · 1 comment
Assignees

Comments

@finnschiermer
Copy link
Contributor

finnschiermer commented Mar 26, 2019

@finnschiermer commented on Mon Mar 25 2019

Reported by the thread sanitizer.

../test/test_async_open.cpp:1957: Begin AsyncOpen_EncryptedServer
==================
WARNING: ThreadSanitizer: data race (pid=23492)
  Read of size 1 at 0x7fa471826017 by thread T16 (mutexes: write M913803392290289048, write M944488891067400320):
    #0 realm::SlabAlloc::get_committed_file_format_version() const ../src/realm/alloc_slab.cpp:748 (realm-sync-tests+0xa0cb7e)
    #1 realm::SharedGroup::do_open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, realm::SharedGroupOptions) ../src/realm/group_shared.cpp:1064 (realm-sync-tests+0xbd1512)
    #2 realm::SharedGroup::open(realm::Replication&, realm::SharedGroupOptions) /home/finn/sync/realm-core/src/realm/group_shared.hpp:871 (realm-sync-tests+0x244931)
    #3 realm::SharedGroup::SharedGroup(realm::Replication&, realm::SharedGroupOptions) /home/finn/sync/realm-core/src/realm/group_shared.hpp:844 (realm-sync-tests+0x244931)
    #4 realm::_impl::state_realm::StateRealms::get_latest_server_version(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../src/realm/noinst/state_realm.cpp:669 (realm-sync-tests+0x85a22f)
    #5 realm::_impl::state_realm::StateRealms::get_compactable_server_version(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../src/realm/noinst/state_realm.cpp:58 (realm-sync-tests+0x85a5ca)
    #6 get_state_realm_compactable_server_version ../src/realm/sync/server.cpp:1263 (realm-sync-tests+0x7f08cc)
    #7 get_max_compactable_server_version ../src/realm/sync/server.cpp:6988 (realm-sync-tests+0x7f08cc)
    #8 worker_integrate_changes_from_downstream ../src/realm/sync/server.cpp:5956 (realm-sync-tests+0x7f08cc)
    #9 worker_process_work_unit ../src/realm/sync/server.cpp:5368 (realm-sync-tests+0x7f268e)
    #10 run ../src/realm/sync/server.cpp:7108 (realm-sync-tests+0x7f4f9c)
    #11 operator() ../src/realm/util/thread_exec_guard.hpp:300 (realm-sync-tests+0x7f4f9c)
    #12 entry_point<realm::util::ThreadExecGuardWithParent<R, P>::State::start(const string*) [with R = (anonymous namespace)::Worker; P = (anonymous namespace)::ServerImpl]::<lambda()> > /home/finn/sync/realm-core/src/realm/util/thread.hpp:442 (realm-sync-tests+0x7f4f9c)
    #13 <null> <null> (libtsan.so.0+0x296bd)

  Previous write of size 8 at 0x7fa471826010 by thread T20 (mutexes: write M346):
    #0 mmap <null> (libtsan.so.0+0x533a0)
    #1 realm::util::EncryptedFileMapping::reclaim_page(unsigned long) ../src/realm/util/encrypted_file_mapping.cpp:593 (realm-sync-tests+0xda8836)
    #2 operator() ../src/realm/util/encrypted_file_mapping.cpp:630 (realm-sync-tests+0xda900e)
    #3 realm::util::EncryptedFileMapping::reclaim_untouched(unsigned long&, unsigned long&) ../src/realm/util/encrypted_file_mapping.cpp:669 (realm-sync-tests+0xda900e)
    #4 realm::util::reclaim_pages_for_file(realm::util::SharedFileInfo&, unsigned long&) ../src/realm/util/file_mapper.cpp:356 (realm-sync-tests+0xdb43cb)
    #5 realm::util::reclaim_pages() ../src/realm/util/file_mapper.cpp:408 (realm-sync-tests+0xdb4981)
    #6 realm::util::reclaimer_loop() ../src/realm/util/file_mapper.cpp:422 (realm-sync-tests+0xdb4e0c)
    #7 void std::__invoke_impl<void, void (*)()>(std::__invoke_other, void (*&&)()) /usr/include/c++/7/bits/invoke.h:60 (realm-sync-tests+0xdb9f89)
    #8 std::__invoke_result<void (*)()>::type std::__invoke<void (*)()>(void (*&&)()) /usr/include/c++/7/bits/invoke.h:95 (realm-sync-tests+0xdb9f89)
    #9 decltype (__invoke((_S_declval<0ul>)())) std::thread::_Invoker<std::tuple<void (*)()> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) /usr/include/c++/7/thread:234 (realm-sync-tests+0xdb9f89)
    #10 std::thread::_Invoker<std::tuple<void (*)()> >::operator()() /usr/include/c++/7/thread:243 (realm-sync-tests+0xdb9f89)
    #11 std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)()> > >::_M_run() /usr/include/c++/7/thread:186 (realm-sync-tests+0xdb9f89)
    #12 <null> <null> (libstdc++.so.6+0xbd57e)

  Mutex M913803392290289048 is already destroyed.

  Mutex M944488891067400320 is already destroyed.

  Mutex M346 (0x7b0c00001e90) created at:
    #0 pthread_mutex_init <null> (libtsan.so.0+0x2c5bd)
    #1 realm::util::Mutex::init_as_regular() ../src/realm/util/thread.hpp:476 (realm-sync-tests+0x1e8fea)
    #2 realm::util::Mutex::Mutex() ../src/realm/util/thread.hpp:453 (realm-sync-tests+0x1e8fea)
    #3 __static_initialization_and_destruction_0 ../src/realm/util/file_mapper.cpp:109 (realm-sync-tests+0x1e8fea)
    #4 _GLOBAL__sub_I_file_mapper.cpp ../src/realm/util/file_mapper.cpp:861 (realm-sync-tests+0x1e8fea)
    #5 __libc_csu_init <null> (realm-sync-tests+0xe0c49c)

  Thread T16 'worker' (tid=23707, running) created by thread T2 at:
    #0 pthread_create <null> (libtsan.so.0+0x2bcfe)
    #1 realm::util::Thread::start(void* (*)(void*), void*) /home/finn/sync/realm-core/src/realm/util/thread.hpp:431 (realm-sync-tests+0x7e3df4)
    #2 start<realm::util::ThreadExecGuardWithParent<R, P>::State::start(const string*) [with R = (anonymous namespace)::Worker; P = (anonymous namespace)::ServerImpl]::<lambda()> > /home/finn/sync/realm-core/src/realm/util/thread.hpp:409 (realm-sync-tests+0x7e3df4)
    #3 start ../src/realm/util/thread_exec_guard.hpp:307 (realm-sync-tests+0x7e3df4)
    #4 start_with_signals_blocked ../src/realm/util/thread_exec_guard.hpp:264 (realm-sync-tests+0x7e3df4)
    #5 run ../src/realm/sync/server.cpp:7565 (realm-sync-tests+0x7e3df4)
    #6 realm::sync::Server::run() ../src/realm/sync/server.cpp:8976 (realm-sync-tests+0x7e41fd)
    #7 realm::fixtures::MultiClientServerFixture::run_server(int) ../test/sync_fixtures.hpp:988 (realm-sync-tests+0x265b1b)
    #8 realm::fixtures::MultiClientServerFixture::start()::{lambda()#1}::operator()() const ../test/sync_fixtures.hpp:755 (realm-sync-tests+0x265b1b)
    #9 realm::test_util::ThreadWrapper::Runner<realm::fixtures::MultiClientServerFixture::start()::{lambda()#1}>::run({lambda()#1}, realm::test_util::ThreadWrapper*) ../test/util/thread_wrapper.hpp:83 (realm-sync-tests+0x265b1b)
    #10 realm::test_util::ThreadWrapper::start<realm::fixtures::MultiClientServerFixture::start()::{lambda()#1}>(realm::fixtures::MultiClientServerFixture::start()::{lambda()#1} const&)::{lambda()#1}::operator()() const ../test/util/thread_wrapper.hpp:40 (realm-sync-tests+0x265b1b)
    #11 void* realm::util::Thread::entry_point<realm::test_util::ThreadWrapper::start<realm::fixtures::MultiClientServerFixture::start()::{lambda()#1}>(realm::fixtures::MultiClientServerFixture::start()::{lambda()#1} const&)::{lambda()#1}>({lambda()#1}) /home/finn/sync/realm-core/src/realm/util/thread.hpp:442 (realm-sync-tests+0x265b1b)
    #12 <null> <null> (libtsan.so.0+0x296bd)

  Thread T20 (tid=23690, running) created by thread T6 at:
    #0 pthread_create <null> (libtsan.so.0+0x2bcfe)
    #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xbd834)
    #2 realm::SlabAlloc::note_reader_start(void*) ../src/realm/alloc_slab.cpp:1069 (realm-sync-tests+0xa0cd2c)
    #3 realm::SharedGroup::do_begin_read(realm::VersionID, bool) ../src/realm/group_shared.cpp:2041 (realm-sync-tests+0xbcb720)
    #4 realm::SharedGroup::begin_write() ../src/realm/group_shared.cpp:1902 (realm-sync-tests+0xbcba2e)
    #5 realm::WriteTransaction::WriteTransaction(realm::SharedGroup&) /home/finn/sync/realm-core/src/realm/group_shared.hpp:763 (realm-sync-tests+0x77d228)
    #6 realm::_impl::ClientStateDownload::initialize_from_new() ../src/realm/noinst/client_state_download.cpp:222 (realm-sync-tests+0x77d228)
    #7 realm::_impl::ClientStateDownload::initialize() ../src/realm/noinst/client_state_download.cpp:191 (realm-sync-tests+0x77fa1a)
    #8 realm::_impl::ClientStateDownload::ClientStateDownload(realm::util::Logger&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, realm::util::Optional<std::array<char, 64ul> >) ../src/realm/noinst/client_state_download.cpp:78 (realm-sync-tests+0x77ffbe)
    #9 realm::_impl::ClientImplBase::Session::activate() ../src/realm/noinst/client_impl_base.cpp:1821 (realm-sync-tests+0x76bd9b)
    #10 realm::_impl::ClientImplBase::Connection::activate_session(std::unique_ptr<realm::_impl::ClientImplBase::Session, std::default_delete<realm::_impl::ClientImplBase::Session> >) ../src/realm/noinst/client_impl_base.cpp:144 (realm-sync-tests+0x76ee7d)
    #11 actualize ../src/realm/sync/client.cpp:1427 (realm-sync-tests+0x6d09cc)
    #12 actualize_and_finalize_session_wrappers ../src/realm/sync/client.cpp:819 (realm-sync-tests+0x6d09cc)
    #13 operator() ../src/realm/sync/client.cpp:595 (realm-sync-tests+0x6d1f8e)
    #14 recycle_and_execute ../src/realm/util/network.hpp:3631 (realm-sync-tests+0x6d1f8e)
    #15 realm::util::network::Service::Impl::execute(std::unique_ptr<realm::util::network::Service::AsyncOper, realm::util::network::Service::LendersOperDeleter>&) ../src/realm/util/network.cpp:1647 (realm-sync-tests+0x690834)
    #16 realm::util::network::Service::Impl::run() ../src/realm/util/network.cpp:1407 (realm-sync-tests+0x690834)
    #17 realm::util::network::Service::run() ../src/realm/util/network.cpp:1776 (realm-sync-tests+0x690834)
    #18 realm::_impl::ClientImplBase::run() ../src/realm/noinst/client_impl_base.hpp:1143 (realm-sync-tests+0x6c23d1)
    #19 realm::sync::Client::run() ../src/realm/sync/client.cpp:1896 (realm-sync-tests+0x6c23d1)
    #20 realm::fixtures::MultiClientServerFixture::run_client(int) ../test/sync_fixtures.hpp:1020 (realm-sync-tests+0x265f59)
    #21 realm::fixtures::MultiClientServerFixture::start()::{lambda()#2}::operator()() const ../test/sync_fixtures.hpp:757 (realm-sync-tests+0x265f59)
    #22 realm::test_util::ThreadWrapper::Runner<realm::fixtures::MultiClientServerFixture::start()::{lambda()#2}>::run({lambda()#2}, realm::test_util::ThreadWrapper*) ../test/util/thread_wrapper.hpp:83 (realm-sync-tests+0x265f59)
    #23 realm::test_util::ThreadWrapper::start<realm::fixtures::MultiClientServerFixture::start()::{lambda()#2}>(realm::fixtures::MultiClientServerFixture::start()::{lambda()#2} const&)::{lambda()#1}::operator()() const ../test/util/thread_wrapper.hpp:40 (realm-sync-tests+0x265f59)
    #24 void* realm::util::Thread::entry_point<realm::test_util::ThreadWrapper::start<realm::fixtures::MultiClientServerFixture::start()::{lambda()#2}>(realm::fixtures::MultiClientServerFixture::start()::{lambda()#2} const&)::{lambda()#1}>({lambda()#1}) /home/finn/sync/realm-core/src/realm/util/thread.hpp:442 (realm-sync-tests+0x265f59)
    #25 <null> <null> (libtsan.so.0+0x296bd)

SUMMARY: ThreadSanitizer: data race ../src/realm/alloc_slab.cpp:748 in realm::SlabAlloc::get_committed_file_format_version() const
==================


@realm-probot[bot] commented on Tue Mar 26 2019

Hey - looks like you forgot to add a T:* label - could you please add one?

@finnschiermer
Copy link
Contributor Author

Fixed by #3270

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants