Skip to content
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

Deprecate automatic stashing #1474

Closed
Neverlord opened this issue Jul 7, 2023 · 1 comment
Closed

Deprecate automatic stashing #1474

Neverlord opened this issue Jul 7, 2023 · 1 comment

Comments

@Neverlord
Copy link
Member

Currently, event-based actors automatically "stash" messages if users skip them in a default handler. Stashing basically means: a skipped message gets put into a stash until an incoming message matched the behavior. Then, all messages from the stash get put back into the mailbox and re-matched again for the next run.

There are some use cases where this work flow makes sense, but all actors have this stash, even if they never use it. It's also easy to shoot yourself in the foot with this implicit skipping, because the constant re-scanning can become expensive. Instead of doing this implicitly, we should instead:

  • Provide an explicit caf::stash class to allow actors that actually need this feature to use it manually.
  • Deprecate skippable_result as well as the default handler in general (set_default_handler) and remove with version 1.0. Event-based actors that receive unexpected inputs should terminate.
  • If users want to deal with unexpected inputs in any other way (like stashing): we should bring back "catch-all" handlers for event-based actors. We don't need to have a special syntax for this, I think. A handler with signature [](message msg) { } (or any cv-qualified version thereof) could be treated as catch-all.

Maybe we can also use this opportunity to get rid of the other special handlers as well. Issue #1423 already suggests using an alternative approach for down messages. Basically just remove the old way instead of "overloading" it. We could get rid of the exit handler as well: just add a [](const exit_msg&) handler to your behavior if you want to "override" the default behavior. In my experience, actors that override the exit handler very rarely switch behaviors. The original idea of separating the exit handlers from the behavior was to allow actors to have "constant" exit handler with changing behaviors, but several years later, I think that's just a non-issue. By going down this route, we could get rid of all of these member variables:

default_handler default_handler_;
error_handler error_handler_;
down_handler down_handler_;
node_down_handler node_down_handler_;
exit_handler exit_handler_;

I think it's also an easier mental model to have (and teach). There's the behavior of an actor that has your message callbacks. If an actors fails to match a message, it panicks (i.e., terminates). Period. Currently, it's: "The behavior has your message callbacks, but then there are these 5 special cases where CAF treats messages differently."

@Neverlord
Copy link
Member Author

We have deprecated set_default_handler, which in turns means we have deprecated the use of skip here. The new way is using a mail_cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant