slawlor / ractor

Rust actor framework
MIT License
1.3k stars 66 forks source link

`post_stop` of children are being called when supervisor fails. #226

Closed gusinacio closed 2 months ago

gusinacio commented 2 months ago

Describe the bug Imagine a supervision tree with A -> B. If A panics its post_stop is not called as expected but ractor terminates all its children via normal stop with reason "Killed" and then post_stop is called for this situation.

The problem is that there's no way to identify on B's post_stop that it's being terminated because its supervisor was killed.

The documentation clearly says about post_stop:

Invoked after an actor has been stopped to perform final cleanup. In the event the actor is terminated with Signal::Kill or has self-> panicked, post_stop won't be called. Panics in post_stop follow the supervision strategy.

For me, the actor should not trigger post_stop because it's a killed event or post_stop should have a parameter to identify the reason.

To Reproduce Steps to reproduce the behavior:

  1. Spawn an Actor A with post_stop
  2. Spawn linked Actor B with post_stop
  3. Send a message to actor A that panics/return an error.
  4. See the post_stop from B being called.

Expected behavior When Actor A panics, it should not trigger post_stop of Actor B.

Additional context Ractor Version: 0.9.7 Rust Version: 1.76.0

slawlor commented 2 months ago

Yes this shouldn't happen, I'll investigate and work on a fix. Thank you for reporting!