[Lldb-commits] [lldb] [lldb][Windows] Don't hang unregistering a pipe before its monitor reads (PR #228111)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 2 05:24:43 PDT 2026


================
@@ -150,6 +155,44 @@ TEST_F(MainLoopTest, MultipleReadsPipeObject) {
 }
 #endif
 
+// Registers read_fd, optionally lets the loop poll it once, and drops the
+// handle while the write end of the pipe is still open.
+static void UnregisterWithOpenWriter(int read_fd, bool poll) {
+  MainLoop loop;
+  Status error;
+  auto handle = loop.RegisterReadObject(
+      std::make_shared<NativeFile>(read_fd, File::eOpenOptionReadOnly, false),
+      [](MainLoopBase &) {}, error);
+  ASSERT_THAT_ERROR(error.ToError(), llvm::Succeeded());
+  if (poll) {
+    loop.AddPendingCallback(
+        [](MainLoopBase &loop) { loop.RequestTermination(); });
+    ASSERT_THAT_ERROR(loop.Run().ToError(), llvm::Succeeded());
+  }
----------------
charles-zablit wrote:

Not really: currently `~PipeEvent` sets `m_ready` and then calls `CancelIoEx` and joins. But there is nothing to cancel yet and because the loop is a `do { ... } while (!m_stopped)`, the thread that just woke up still issues a `ReadFile`. Nothing cancels the read so the `join()` hangs while the writer stays open. The no-poll iteration are the root cause of that hang.

With the fix however, the loop is `while (!m_stopped)`, so  the thread exits without reading and the destructor is actually a no-op.

https://github.com/llvm/llvm-project/pull/228111


More information about the lldb-commits mailing list