slawlor / ractor

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

[factory] Bug in worker lifecycle management #118

Closed slawlor closed 1 year ago

slawlor commented 1 year ago

This PR solves a small bug in worker lifecycle management.

currently If the factory has a queue of backlogged work, and a worker dies, when it's restarted, it won't immediately dequeue the next message from the factory's queue. It will only get a message on the next incoming factory message which additionally since there's a "free" worker, even with a backlog of work, that incoming message will jump the queue.

This is incorrect behavior, and queue'd message should be served first. This change makes it that when a worker is re-created, it will dequeue a message as the worker is now "free".

Tests added to cover this scenario going forward.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 87.96% and project coverage change: +0.33 :tada:

Comparison is base (a40d75b) 79.60% compared to head (498df63) 79.93%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #118 +/- ## ========================================== + Coverage 79.60% 79.93% +0.33% ========================================== Files 49 50 +1 Lines 8761 8863 +102 ========================================== + Hits 6974 7085 +111 + Misses 1787 1778 -9 ``` | [Impacted Files](https://app.codecov.io/gh/slawlor/ractor/pull/118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor) | Coverage Δ | | |---|---|---| | [ractor/src/factory/tests/mod.rs](https://app.codecov.io/gh/slawlor/ractor/pull/118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9mYWN0b3J5L3Rlc3RzL21vZC5ycw==) | `91.40% <50.00%> (ø)` | | | [ractor/src/factory/mod.rs](https://app.codecov.io/gh/slawlor/ractor/pull/118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9mYWN0b3J5L21vZC5ycw==) | `83.98% <70.45%> (+5.27%)` | :arrow_up: | | [ractor/src/factory/tests/worker\_lifecycle.rs](https://app.codecov.io/gh/slawlor/ractor/pull/118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9mYWN0b3J5L3Rlc3RzL3dvcmtlcl9saWZlY3ljbGUucnM=) | `97.64% <97.64%> (ø)` | | | [ractor/src/factory/stats.rs](https://app.codecov.io/gh/slawlor/ractor/pull/118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9mYWN0b3J5L3N0YXRzLnJz) | `57.81% <100.00%> (-0.33%)` | :arrow_down: | | [ractor/src/factory/worker.rs](https://app.codecov.io/gh/slawlor/ractor/pull/118?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor#diff-cmFjdG9yL3NyYy9mYWN0b3J5L3dvcmtlci5ycw==) | `88.63% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.