[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:16:49 PST 2023
https://github.com/jimingham created https://github.com/llvm/llvm-project/pull/71997
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.
>From d76a7dec707e484e501b45a32066f852cba8de95 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Fri, 10 Nov 2023 15:08:19 -0800
Subject: [PATCH] Fix a little thinko in sending events to secondary listeners.
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.
---
lldb/source/Utility/Broadcaster.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
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 {
More information about the lldb-commits
mailing list