[Lldb-commits] [lldb] Fix a little thinko in sending events to secondary listeners. (PR #71997)

via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 10 15:17:20 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: None (jimingham)

<details>
<summary>Changes</summary>

If `unique` is true, I was redoing the uniqueness check for the secondary listeners, which is racy since a "duplicate" event could come in between deciding to send the event to the main listener and checking for the shadow listener, and then the two streams would get out of sync.

There's not a good way to write a direct test for this, but the test_shadow_listeners test has been flakey and this is the only racy part of that system I can find.  So the test would be that that test_shadow_listeners becomes not flakey.

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


1 Files Affected:

- (modified) lldb/source/Utility/Broadcaster.cpp (+5-5) 


``````````diff
diff --git a/lldb/source/Utility/Broadcaster.cpp b/lldb/source/Utility/Broadcaster.cpp
index 5192502addbdd72..914812d7857779f 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -280,13 +280,13 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp,
     // Make sure to do this before adding the event to the primary or it might
     // start handling the event before we're done adding all the pending
     // listeners.
+    // Also, don't redo the check for unique here, since otherwise that could
+    // be racy, and if we send the event to the primary listener then we SHOULD 
+    // send it to the secondary listeners or they will get out of sync with the
+    // primary listener.
     if (!hijacking_listener_sp) {
-      for (auto &pair : GetListeners(event_type, false)) {
-        if (unique && pair.first->PeekAtNextEventForBroadcasterWithType(
-                          &m_broadcaster, event_type))
-          continue;
+      for (auto &pair : GetListeners(event_type, false))
         event_sp->AddPendingListener(pair.first);
-      }
     }
     primary_listener_sp->AddEvent(event_sp);
   } else {

``````````

</details>


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


More information about the lldb-commits mailing list