-
Notifications
You must be signed in to change notification settings - Fork 35
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
Change default implementation of Actor::stopping
#58
Change default implementation of Actor::stopping
#58
Conversation
Returning `StopAll` is a dangerous default because it makes supervisor patterns hard to implement. With `StopAll`, spawning a new instance of an actor in a context if the old one dies results in the newly created actor to also be shut down.
f8663e7
to
c859545
Compare
I'm okay with this in principle, but there is one footgun that would be good if we could avoid: |
It is interesting that you are calling this a footgun because I would have expected Is that not what you intended with this function? |
Maybe this is a flaw in my mental model - originally, xtra could not have multiple actors on the same address, so I guess I still think of |
I haven't personally used multiple actors on the same address with All of our actors track some kind of state and load-balancing all messages across all instances doesn't play well with that. For the case where we have multiple instances of the same actor running, I'd usually need to route to a very concrete instance (because its internal state is relevant to the incoming message). It might be worthwhile to consider cloning the messages and sending it to all actors on an address. Then the instances that don't care could just drop the message. Coming back to Another use of So, however it is exposed, there should IMO be a way of terminating just the one instance of the actor that is handling a message. |
Ah, ok. My usecase was for database actors, or search actors where they share some data that is internally synchronised, so they are stateless in and of themselves.
This can be done with Context::broadcast or similar
How do you mean passing along a value?
Of course :) |
Something like: I am not sure if it is easy to balance all the tradeoffs:
So perhaps it is not great ideal overall. For RAII actors, it is usually pretty clear as to why they are stopping (some error occurred and the connection is unusable) and having to store that as state just to retrieve it again in |
Would that return value then be passed to |
Either that or we directly return it.
In some ways it is ergonomics but there is another subtly to it. Managing the |
That's true! I think it could definitely be a good change. |
I just realized an unintended side-effect of this change: I'll see to add a test for this and then check if we can still return |
I've opened a PR that demonstrates what I would consider to be a bug: #60 |
Closing in favor of #64. |
Returning
StopAll
is a dangerous default because it makes supervisorpatterns hard to implement. With
StopAll
, spawning a new instance ofan actor in a context if the old one dies results in the newly created
actor to also be shut down.
See get10101/itchysats@dc5c6bd.