Commit eb3ecd99 authored by Marian Triebe's avatar Marian Triebe

Fix a bug with actors not leaving their groups

This bug was reported on the mailing list
parent 0a1342aa
......@@ -110,10 +110,10 @@ class abstract_actor : public abstract_channel {
/**
* Detaches the first attached object that matches `what`.
*/
void detach(const attachable::token& what);
size_t detach(const attachable::token& what);
template <class T>
void detach(const T& what) {
size_t detach(const T& what) {
return detach(attachable::token{typeid(T), &what});
}
......
......@@ -41,6 +41,7 @@ namespace caf {
class group;
class serializer;
class local_actor;
class deserializer;
/**
......@@ -50,6 +51,7 @@ class abstract_group : public abstract_channel {
public:
friend class detail::group_manager;
friend class detail::peer_connection;
friend class local_actor;
~abstract_group();
......
......@@ -87,11 +87,14 @@ size_t abstract_actor::detach_impl(const attachable::token& what,
attachable_ptr& ptr,
bool stop_on_hit,
bool dry_run) {
CAF_LOGF_TRACE("");
if (!ptr) {
CAF_LOGF_DEBUG("invalid ptr");
return 0;
}
if (ptr->matches(what)) {
if (!dry_run) {
CAF_LOGF_DEBUG("removed element");
attachable_ptr next;
next.swap(ptr->next);
ptr.swap(next);
......@@ -101,10 +104,10 @@ size_t abstract_actor::detach_impl(const attachable::token& what,
return detach_impl(what, ptr->next, stop_on_hit, dry_run);
}
void abstract_actor::detach(const attachable::token& what) {
size_t abstract_actor::detach(const attachable::token& what) {
CAF_LOG_TRACE("");
guard_type guard{m_mtx};
detach_impl(what, m_attachables_head);
return detach_impl(what, m_attachables_head);
}
bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) {
......
......@@ -76,10 +76,13 @@ void local_actor::join(const group& what) {
}
void local_actor::leave(const group& what) {
CAF_LOG_TRACE(CAF_TSARG(what));
if (what == invalid_group) {
return;
}
detach(abstract_group::subscription_token{what.ptr()});
if (detach(abstract_group::subscription_token{what.ptr()}) > 0) {
what->unsubscribe(address());
}
}
std::vector<group> local_actor::joined_groups() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment