forked from actor-framework/actor-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix unbounded attachable growth when monitoring actors exit #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jachris
wants to merge
5
commits into
main
Choose a base branch
from
fix/monitor-attachable-growth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
308452d
Add `actor_clock` setter to `actor_system_config`
jachris e4080f1
Revert "Avoid using init_fun for spawning function objects"
IyeOnline 99506c9
Fix detached actors starving on scheduler worker threads
e126005
Fix unbounded attachable growth when monitoring actors exit
jachris 7ffc5da
Fix unbounded attachable growth in the legacy monitor() API
jachris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // This file is part of CAF, the C++ Actor Framework. See the file LICENSE in | ||
| // the main distribution directory for license terms and copyright or visit | ||
| // https://github.com/actor-framework/actor-framework/blob/main/LICENSE. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "caf/action.hpp" | ||
| #include "caf/actor.hpp" | ||
| #include "caf/actor_addr.hpp" | ||
| #include "caf/actor_cast.hpp" | ||
| #include "caf/attachable.hpp" | ||
| #include "caf/detail/monitor_action.hpp" | ||
| #include "caf/mailbox_element.hpp" | ||
|
|
||
| namespace caf::detail { | ||
|
|
||
| /// Token used to identify and remove a `monitor_attachable` via `detach()`. | ||
| struct monitor_token { | ||
| abstract_monitor_action* key; | ||
| static constexpr size_t token_type = attachable::token::monitor; | ||
| }; | ||
|
|
||
| /// Attachable placed on the monitored actor. Unlike `functor_attachable` it | ||
| /// carries a matchable token so it can be removed via `abstract_actor::detach()` | ||
| /// when the monitoring actor exits or cancels the monitor. | ||
| class monitor_attachable : public attachable { | ||
| public: | ||
| static constexpr size_t token_type = attachable::token::monitor; | ||
|
|
||
| monitor_attachable(abstract_monitor_action_ptr on_down, actor_addr self) | ||
| : on_down_(std::move(on_down)), self_(std::move(self)) {} | ||
|
|
||
| void actor_exited(const error& reason, scheduler* sched) override { | ||
| if (on_down_->set_reason(error{reason})) { | ||
| if (auto shdl = actor_cast<actor>(self_)) | ||
| shdl->enqueue( | ||
| make_mailbox_element(nullptr, make_message_id(), action{on_down_}), | ||
| sched); | ||
| } | ||
| } | ||
|
|
||
| bool matches(const token& what) override { | ||
| if (what.subtype != token_type) | ||
| return false; | ||
| return static_cast<const monitor_token*>(what.ptr)->key == on_down_.get(); | ||
| } | ||
|
|
||
| private: | ||
| abstract_monitor_action_ptr on_down_; | ||
| actor_addr self_; | ||
| }; | ||
|
|
||
| } // namespace caf::detail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weak_actor_ptrs keep the control blocks that are pointed to alive, so we need to remove entries from this map non-lazily. I think that needs to be done indo_demonitor(), but also when adown_msg(+node_down_msg?) is processed in scheduled actors. For completeness we might also want to do the same in blocking actors.