Skip to content

[lldb-dap] Fixing a race during disconnect. #135872

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

Merged
merged 1 commit into from
Apr 16, 2025

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented Apr 15, 2025

While attempting to disconnect the DAP transport reader thread is setting
disconnecting as soon as it sees a disconnect request.

However, if it is processing another request when this 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.

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.
@llvmbot
Copy link
Member

llvmbot commented Apr 15, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

While attempting to disconnect the DAP transport reader thread is setting
disconnecting as soon as it sees a disconnect request.

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.


Full diff: https://github.com/llvm/llvm-project/pull/135872.diff

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/DAP.cpp (+1-1)
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<std::mutex> lock(m_queue_mutex);
     m_queue_cv.wait(lock, [&] { return disconnecting || !m_queue.empty(); });
 

@ashgti ashgti merged commit 183cb45 into llvm:main Apr 16, 2025
13 checks passed
@ashgti ashgti deleted the lldb-dap-disconnect-race branch April 16, 2025 14:52
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
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 this 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants