slawlor / ractor

Rust actor framework
MIT License
1.31k stars 68 forks source link

Add monitoring of actors from peers, without full linking support. #170

Closed slawlor closed 9 months ago

slawlor commented 9 months ago

Motivation

linking an actor to another actor, in ractor, invokes the parent-child relationship and makes the parent the supervisor of the child. This means if the parent dies, before the child can process a supervision event (in say a doubly-linked scenario), the child will be terminated as part of the parent's exit flow (and not just terminated, but killed halting any async work in any flow).

This is non-ideal for looser ownership scenarios.

This PR introduces the notion of monitoring (along with unmonitor and clear_monitors) which allows a non-parent relationship to supervision. This means an actor can monitor another actor without being in the direct lifecycle path yet still receive supervision events.

NOTE: In order to not require the state to implement Clone, we instead add a "slimmed out" supervision event for monitors, such that they (a) won't receive the actor's state upon a termination event, if available at all, and (b) won't receive the actual exception with potential extra information, rather a serialized string version. This helps require that the underlying Actor::State be as limited in trait implementations as possible (just Send + 'static)

Tests added on new functionality

codecov[bot] commented 9 months ago

Codecov Report

Patch coverage: 94.70% and project coverage change: +0.29% :tada:

Comparison is base (bb33d4f) 78.91% compared to head (8a3ed35) 79.20%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #170 +/- ## ========================================== + Coverage 78.91% 79.20% +0.29% ========================================== Files 49 49 Lines 8977 9123 +146 ========================================== + Hits 7084 7226 +142 - Misses 1893 1897 +4 ``` | [Files Changed](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor) | Coverage Δ | | |---|---|---| | [ractor/src/pg/mod.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9wZy9tb2QucnM=) | `72.32% <ø> (ø)` | | | [ractor/src/registry/pid\_registry.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9yZWdpc3RyeS9waWRfcmVnaXN0cnkucnM=) | `93.65% <ø> (ø)` | | | [ractor/src/actor/messages.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9hY3Rvci9tZXNzYWdlcy5ycw==) | `68.18% <60.00%> (-1.47%)` | :arrow_down: | | [ractor/src/actor/tests/supervisor.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9hY3Rvci90ZXN0cy9zdXBlcnZpc29yLnJz) | `92.12% <96.03%> (+0.40%)` | :arrow_up: | | [ractor/src/actor/actor\_cell.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9hY3Rvci9hY3Rvcl9jZWxsLnJz) | `95.00% <100.00%> (+0.31%)` | :arrow_up: | | [ractor/src/actor/actor\_ref.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9hY3Rvci9hY3Rvcl9yZWYucnM=) | `86.11% <100.00%> (ø)` | | | [ractor/src/actor/mod.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9hY3Rvci9tb2QucnM=) | `90.22% <100.00%> (+0.09%)` | :arrow_up: | | [ractor/src/actor/supervision.rs](https://app.codecov.io/gh/slawlor/ractor/pull/170?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9hY3Rvci9zdXBlcnZpc2lvbi5ycw==) | `98.43% <100.00%> (+0.65%)` | :arrow_up: | ... and [3 files with indirect coverage changes](https://app.codecov.io/gh/slawlor/ractor/pull/170/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.