fix(wave11): resolve adversarial review findings in EventBus, IO, and Runtime

This commit is contained in:
faumaray committed 2026-12-01 22:03:35 +03:00
1 parent 7bea7df46d
commit c6de7842f7
10 files changed
+871 -134

No files matched your search

+36 -36
View File
@@ -240,6 +240,27 @@ struct BusCore : std::enable_shared_from_this<BusCore> {
}
}
void finish_entry_dispatch(const std::shared_ptr<SubEntry>& entry) noexcept
{
for (;;) {
std::function<void(const void*)> cleanup_fn;
{
std::lock_guard lk{mu};
if (!entry->active && entry->in_flight == 1 && entry->handler) {
cleanup_fn = std::move(entry->handler);
} else {
--entry->in_flight;
--total_in_flight;
break;
}
}
// Destroy captured state outside mu while in_flight >= 1 so
// join_entry / close_and_join / ~EventBus cannot return early.
cleanup_fn = {};
}
done_cv.notify_all();
}
[[nodiscard]] Void::Result::Result<void> join_entry(
const std::shared_ptr<SubEntry>& entry)
{
@@ -298,10 +319,11 @@ struct BusCore : std::enable_shared_from_this<BusCore> {
const void* ev_raw = item.event.get();
for (auto& rec : item.recipients) {
std::function<void(const void*)> fn;
std::function<void(const void*)> discarded_legacy;
{
std::lock_guard lk{mu};
if (closed || rec.entry->purged) {
rec.legacy_fn = {};
discarded_legacy = std::move(rec.legacy_fn);
continue;
}
if (!rec.legacy_fn && !rec.entry->active) {
@@ -326,18 +348,7 @@ struct BusCore : std::enable_shared_from_this<BusCore> {
}
fn = {};
std::function<void(const void*)> cleanup_fn;
{
std::lock_guard lk{mu};
--rec.entry->in_flight;
--total_in_flight;
if (!rec.entry->active && rec.entry->in_flight == 0 &&
rec.entry->handler) {
cleanup_fn = std::move(rec.entry->handler);
}
}
done_cv.notify_all();
cleanup_fn = {};
finish_entry_dispatch(rec.entry);
}
// Destroy event payload and recipient handles before completion notify.
@@ -460,17 +471,7 @@ inline DispatchCoroutine make_injected_dispatch(
}
fn = {};
std::function<void(const void*)> cleanup_fn;
{
std::lock_guard lk{core->mu};
--entry->in_flight;
--core->total_in_flight;
if (!entry->active && entry->in_flight == 0 && entry->handler) {
cleanup_fn = std::move(entry->handler);
}
}
core->done_cv.notify_all();
cleanup_fn = {};
core->finish_entry_dispatch(entry);
}
snapshot.clear();
@@ -709,18 +710,7 @@ public:
~EntryExitGuard()
{
fn_ref = {};
std::function<void(const void*)> cleanup;
{
std::lock_guard lk{core->mu};
--entry->in_flight;
--core->total_in_flight;
if (!entry->active && entry->in_flight == 0 &&
entry->handler) {
cleanup = std::move(entry->handler);
}
}
core->done_cv.notify_all();
cleanup = {};
core->finish_entry_dispatch(entry);
}
} exit_guard{core, entry, fn};
@@ -933,6 +923,11 @@ public:
Void::Async::AsyncErrorCode::invalid_argument,
"EventBus::flush_pumping requires a matching ManualExecutor")};
}
if (detail::is_on_bus_callback(core_.get())) {
return std::unexpected{Void::Async::make_async_error(
Void::Async::AsyncErrorCode::self_join,
"EventBus::flush_pumping cannot be called from inside a callback")};
}
std::uint64_t target = 0;
{
std::lock_guard lk{core_->mu};
@@ -1036,6 +1031,11 @@ public:
Void::Async::AsyncErrorCode::invalid_argument,
"EventBus::close_and_join_pumping requires a matching ManualExecutor")};
}
if (detail::is_on_bus_callback(core_.get())) {
return std::unexpected{Void::Async::make_async_error(
Void::Async::AsyncErrorCode::self_join,
"EventBus::close_and_join_pumping cannot be called from inside a callback")};
}
std::vector<std::function<void(const void*)>> to_drop;
{