From bf88d1c2f4a4681d7df7d4d540b3c3b046778ff7 Mon Sep 17 00:00:00 2001 From: Dominik Lohmann Date: Wed, 17 Jan 2024 12:58:07 +0100 Subject: [PATCH] Integrate review feedback --- libcaf_core/caf/actor_control_block.hpp | 4 +++- libcaf_core/src/response_promise.cpp | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libcaf_core/caf/actor_control_block.hpp b/libcaf_core/caf/actor_control_block.hpp index fc32981858..9e11609452 100644 --- a/libcaf_core/caf/actor_control_block.hpp +++ b/libcaf_core/caf/actor_control_block.hpp @@ -136,7 +136,9 @@ CAF_CORE_EXPORT void intrusive_ptr_release_weak(actor_control_block* x); /// @relates actor_control_block inline void intrusive_ptr_add_ref(actor_control_block* x) { - x->strong_refs.fetch_add(1, std::memory_order_relaxed); + if (CAF_UNLIKELY(x->strong_refs.fetch_add(1, std::memory_order_relaxed) == 0)) { + CAF_CRITICAL("increased the strong reference count of an expired actor"); + } } /// @relates actor_control_block diff --git a/libcaf_core/src/response_promise.cpp b/libcaf_core/src/response_promise.cpp index 672ccdc23c..634d399901 100644 --- a/libcaf_core/src/response_promise.cpp +++ b/libcaf_core/src/response_promise.cpp @@ -167,12 +167,16 @@ void response_promise::state::cancel() { void response_promise::state::deliver_impl(message msg) { CAF_LOG_TRACE(CAF_ARG(msg)); auto cancel_guard = detail::make_scope_guard([this] { - cancel(); - }); + cancel(); + }); if (msg.empty() && id.is_async()) { CAF_LOG_DEBUG("drop response: empty response to asynchronous input"); return; } + if (source == nullptr) { + CAF_LOG_DEBUG("drop response: source is nullptr"); + return; + } auto self = weak_self.lock(); if (self == nullptr) { auto element = make_mailbox_element(self, id.response_id(), @@ -181,7 +185,7 @@ void response_promise::state::deliver_impl(message msg) { source->enqueue(std::move(element), nullptr); return; } - auto local_self = static_cast(weak_self.get()->get()); + auto local_self = static_cast(self->get()); if (!stages.empty()) { auto next = std::move(stages.back()); stages.pop_back(); @@ -189,7 +193,6 @@ void response_promise::state::deliver_impl(message msg) { local_self->context(), std::move(msg)); return; } - CAF_ASSERT(source != nullptr); detail::profiled_send(local_self, local_self->ctrl(), source, id.response_id(), forwarding_stack{}, local_self->context(), std::move(msg)); }