You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Re-verified against rivetkit-core's shutdown sequence (ActorTask::run_shutdown in rivetkit-rust/packages/rivetkit-core/src/actor/task.rs); the fix is correct and this comment supersedes my prior pass.
Root cause confirmed:run_shutdown calls save_final_state() (which sends ActorEvent::SerializeState) before close_actor_event_channel(). Previously, handle_actor_event returned Ok(true) right after handling RunGracefulCleanup, breaking the run_actor loop and dropping the Events<A> receiver. When core then tried to send the follow-up SerializeState event, the enqueue failed (send_actor_event -> not_ready), and core fell back to self.ctx.save_state(Vec::new()).await, discarding any state written by on_sleep/on_destroy. The new code correctly lets the loop keep running until core itself drops the sender via close_actor_event_channel() (task.rs:1494-1497), matching the pattern already used by the NAPI runtime (napi_actor_events.rs, which never terminates its dispatch loop on RunGracefulCleanup either).
I also checked whether this can deadlock if run_shutdown's inner block returns early (e.g. save_state fails before reaching close_actor_event_channel()): it cannot, because ActorTask::run takes self by value and returns right after, so actor_event_tx is dropped when the task struct itself goes out of scope regardless of the early return. No hang risk.
Test coverage:run_actor_serializes_state_after_cleanup is a solid regression test. It would fail under the old code since tx.send(SerializeState) happens after the loop already exited and dropped the receiver. Good that it asserts on the actual on_sleep-written log entry rather than just "no error." The mechanical drop(tx) additions across the other lifecycle tests are consistent and necessary now that the loop no longer self-terminates on RunGracefulCleanup; every request_sleep/request_destroy call site got the corresponding drop(tx).
Minor (non-blocking) nit:handle_actor_event's Result<bool> return and the should_stop/break in run_actor (start.rs:249-252) are now dead code. No match arm returns Ok(true) anymore, so should_stop is always false and the loop only ever ends via events.recv_raw() returning None. Worth collapsing to Result<()> (or a one-line comment noting it is kept for a future early-stop case) so the dead branch does not linger.
Scope is minimal and confined to rivetkit-rust/packages/rivetkit/src/start.rs, consistent with this crate's role as a thin wrapper. No bugs, security, or performance concerns found. Nothing blocking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.