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

Debug build of TSAN reports race in safepoint handler #47788

Open
mkustermann opened this issue Nov 26, 2021 · 0 comments
Open

Debug build of TSAN reports race in safepoint handler #47788

mkustermann opened this issue Nov 26, 2021 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening

Comments

@mkustermann
Copy link
Member

When building Debug mode TSAN the app-jit training will lead to

WARNING: ThreadSanitizer: data race (pid=2860556)
  Write of size 8 at 0x7b2000000a70 by thread T7 (mutexes: write M827):
    #0 dart::SafepointHandler::LevelHandler::SetSafepointInProgress(dart::Thread*) ../../out/DebugTSANX64/../../runtime/vm/heap/safepoint.h:112:14 (dart+0x2a5013c)
    #1 dart::SafepointHandler::SafepointThreads(dart::Thread*, dart::SafepointLevel) ../../out/DebugTSANX64/../../runtime/vm/heap/safepoint.cc:120:23 (dart+0x2a4f0a1)
    #2 dart::SafepointOperationScope::SafepointOperationScope(dart::Thread*, dart::SafepointLevel) ../../out/DebugTSANX64/../../runtime/vm/heap/safepoint.cc:21:12 (dart+0x2a4ed88)
    #3 dart::GcSafepointOperationScope::GcSafepointOperationScope(dart::Thread*) ../../out/DebugTSANX64/../../runtime/vm/heap/safepoint.h:34:9 (dart+0x264b0bb)
    #4 dart::Heap::NotifyIdle(long) ../../out/DebugTSANX64/../../runtime/vm/heap/heap.cc:367:31 (dart+0x2a326a2)
    #5 dart::IdleTimeHandler::NotifyIdle(long) ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:236:12 (dart+0x2643b54)
    #6 dart::IdleTimeHandler::NotifyIdleUsingDefaultDeadline() ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:247:3 (dart+0x2643c1b)
    #7 dart::MutatorThreadPool::NotifyIdle() ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:324:40 (dart+0x26441bc)
    #8 dart::MutatorThreadPool::OnEnterIdleLocked(dart::MonitorLocker*) ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:313:5 (dart+0x2643fec)
    #9 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*) ../../out/DebugTSANX64/../../runtime/vm/thread_pool.cc:183:7 (dart+0x29d5554)
    #10 dart::ThreadPool::Worker::Main(unsigned long) ../../out/DebugTSANX64/../../runtime/vm/thread_pool.cc:339:9 (dart+0x29d6567)
    #11 dart::ThreadStart(void*) ../../out/DebugTSANX64/../../runtime/vm/os_thread_linux.cc:154:5 (dart+0x2881e12)

  Previous read of size 8 at 0x7b2000000a70 by main thread:
    [failed to restore the stack]

  Location is heap block of size 128 at 0x7b2000000a00 allocated by main thread:
    #0 operator new(unsigned long) ../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/tsan_new_delete.cpp:64:3 (dart+0x2139ff6)
    #1 dart::SafepointHandler::SafepointHandler(dart::IsolateGroup*) ../../out/DebugTSANX64/../../runtime/vm/heap/safepoint.cc:76:7 (dart+0x2a4f9e2)
    #2 dart::IsolateGroup::IsolateGroup(std::__2::shared_ptr<dart::IsolateGroupSource>, void*, dart::ObjectStore*, Dart_IsolateFlags) ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:349:30 (dart+0x2644a49)
    #3 dart::IsolateGroup::IsolateGroup(std::__2::shared_ptr<dart::IsolateGroupSource>, void*, Dart_IsolateFlags) ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:408:7 (dart+0x264649f)
    #4 Dart_CreateIsolateGroup ../../out/DebugTSANX64/../../runtime/vm/dart_api_impl.cc:1405:20 (dart+0x32818bc)
    #5 dart::bin::CreateIsolateGroupAndSetupHelper(bool, char const*, char const*, char const*, Dart_IsolateFlags*, void*, char**, int*) ../../out/DebugTSANX64/../../runtime/bin/main.cc:791:15 (dart+0x214e6f4)
    #6 dart::bin::RunMainIsolate(char const*, char const*, dart::bin::CommandLineOptions*) ../../out/DebugTSANX64/../../runtime/bin/main.cc:976:26 (dart+0x214d8ae)
    #7 dart::bin::main(int, char**) ../../out/DebugTSANX64/../../runtime/bin/main.cc:1348:7 (dart+0x214f407)
    #8 main ../../out/DebugTSANX64/../../runtime/bin/main.cc:1386:3 (dart+0x21504a8)

  Mutex M827 (0x7b1c000000e0) created at: 
    #0 pthread_mutex_init ../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1295:3 (dart+0x20c2cff)
    #1 dart::Monitor::Monitor() ../../out/DebugTSANX64/../../runtime/vm/os_thread_linux.cc:372:12 (dart+0x2882fe5)
    #2 dart::ThreadRegistry::ThreadRegistry() ../../out/DebugTSANX64/../../runtime/vm/thread_registry.h:25:22 (dart+0x26458f9)
    #3 dart::IsolateGroup::IsolateGroup(std::__2::shared_ptr<dart::IsolateGroupSource>, void*, dart::ObjectStore*, Dart_IsolateFlags) ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:348:28 (dart+0x2644a08)
    #4 dart::IsolateGroup::IsolateGroup(std::__2::shared_ptr<dart::IsolateGroupSource>, void*, Dart_IsolateFlags) ../../out/DebugTSANX64/../../runtime/vm/isolate.cc:408:7 (dart+0x264649f)
    #5 Dart_CreateIsolateGroup ../../out/DebugTSANX64/../../runtime/vm/dart_api_impl.cc:1405:20 (dart+0x32818bc)
    #6 dart::bin::CreateIsolateGroupAndSetupHelper(bool, char const*, char const*, char const*, Dart_IsolateFlags*, void*, char**, int*) ../../out/DebugTSANX64/../../runtime/bin/main.cc:791:15 (dart+0x214e6f4)
    #7 dart::bin::RunMainIsolate(char const*, char const*, dart::bin::CommandLineOptions*) ../../out/DebugTSANX64/../../runtime/bin/main.cc:976:26 (dart+0x214d8ae)
    #8 dart::bin::main(int, char**) ../../out/DebugTSANX64/../../runtime/bin/main.cc:1348:7 (dart+0x214f407)
    #9 main ../../out/DebugTSANX64/../../runtime/bin/main.cc:1386:3 (dart+0x21504a8)

The read in question here - which is not captured by TSAN due to pruning of old stacks - is caused by a debug-mode only assert.

@mkustermann mkustermann added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening labels Nov 26, 2021
copybara-service bot pushed a commit that referenced this issue Nov 26, 2021
The SafepointHandler::IsOwnedByTheThread() is used in a few
ASSERT()/RELEASE_ASSERT() and accesses the [owner_] field
unsynchronized.

Issue #47788

TEST=Fixes one race reported when building TSAN in DEBUG mode.

Change-Id: I64371265d60c9bb68c299d1c1e8abc2175b33bc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221331
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening
Projects
None yet
Development

No branches or pull requests

1 participant