Issue 138152
Summary Unsynchronized access to `disconnecting` in lldb-dap
Labels new issue
Assignees
Reporter JDevlieghere
    TSan report:
```
WARNING: ThreadSanitizer: data race (pid=7657)
  Write of size 1 at 0x00016d0e1fb0 by thread T4:
 #0 std::__1::__async_func<lldb_dap::DAP::Loop()::$_0>::operator()[abi:nn190102]() future:1827 (lldb-dap:arm64+0x100023230)
    #1 std::__1::__async_assoc_state<lldb::SBError, std::__1::__async_func<lldb_dap::DAP::Loop()::$_0>>::__execute() future:841 (lldb-dap:arm64+0x100023084)
    #2 void* std::__1::__thread_proxy[abi:nn190102]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (std::__1::__async_assoc_state<lldb::SBError, std::__1::__async_func<lldb_dap::DAP::Loop()::$_0>>::*)(), std::__1::__async_assoc_state<lldb::SBError, std::__1::__async_func<lldb_dap::DAP::Loop()::$_0>>*>>(void*) <null> (lldb-dap:arm64+0x100025874)

  Previous read of size 1 at 0x00016d0e1fb0 by main thread:
    #0 lldb_dap::DAP::Loop() DAP.cpp:941 (lldb-dap:arm64+0x100016218)
    #1 main lldb-dap.cpp:606 (lldb-dap:arm64+0x100005f08)

  Location is stack of main thread.

 Thread T4 (tid=492699, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x32af8)
 #1 lldb_dap::DAP::Loop() DAP.cpp:868 (lldb-dap:arm64+0x100016170)
    #2 main lldb-dap.cpp:606 (lldb-dap:arm64+0x100005f08)

SUMMARY: ThreadSanitizer: data race future:1827 in 
std::__1::__async_func<lldb_dap::DAP::Loop()::$_0>::operator()[abi:nn190102]()
```

On the main thread:
```
frame #13: 0x0000000104626254 lldb-dap`lldb_dap::DAP::Loop(this=0x000000016b7eda08) at DAP.cpp:943:16 [opt]
   940      StopEventHandlers();
   941    });
   942
-> 943 while (!disconnecting || !m_queue.empty()) {
   944 std::unique_lock<std::mutex> lock(m_queue_mutex);
   945 m_queue_cv.wait(lock, [&] { return disconnecting || !m_queue.empty(); });
 946
```

On the `stdin/stdout.transport_handler` thread:

```
frame #8: 0x0000000104633234 lldb-dap`std::__1::__async_func<lldb_dap::DAP::Loop()::$_0>::operator()[abi:nn190102]() [inlined] lldb_dap::DAP::Loop(this=<unavailable>)::$_0::operator()() const::'lambda'()::operator()() const at DAP.cpp:872:25 [opt]
   869 llvm::set_thread_name(transport.GetClientName() + ".transport_handler");
 870          auto cleanup = llvm::make_scope_exit([&]() {
   871 // Ensure we're marked as disconnecting when the reader exits.
-> 872 std::unique_lock<std::mutex> lock(m_queue_mutex);
   873 disconnecting = true;
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to