From 07368faf51f5872b5603d1401837ef44f9b5b391 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Tue, 15 Apr 2025 15:08:43 -0700 Subject: [PATCH] [lldb-dap] Fixing a race during disconnect. While attempting to disconnect the DAP transport reader thread is setting `disconnecting` as soon as it sees a [disconnect request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect). However, if it is processing another request when ths disconnect arrives the `DAP::Loop` handler may exit the loop without replying to the disconnect request. There has been some instability on the CI jobs due to this race, for example https://lab.llvm.org/buildbot/#/builders/59/builds/16076 To address this, ensure we only return from `DAP::Loop` once we've emptied the queue. --- lldb/tools/lldb-dap/DAP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index b752e9cfaeb85..597fe3a1e323b 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -921,7 +921,7 @@ llvm::Error DAP::Loop() { StopEventHandlers(); }); - while (!disconnecting) { + while (!disconnecting || !m_queue.empty()) { std::unique_lock lock(m_queue_mutex); m_queue_cv.wait(lock, [&] { return disconnecting || !m_queue.empty(); });