Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions rivetkit-rust/packages/rivetkit-core/src/actor/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,12 +1534,22 @@ impl ActorTask {
}
}

/// Escalate a sleep grace to a destroy so `ctx.destroy()` called during the
/// sleep handler is honored instead of finalizing as a sleep.
fn finalize_shutdown_reason(&self, grace_reason: ShutdownKind) -> ShutdownKind {
if grace_reason == ShutdownKind::Sleep && self.ctx.destroy_requested() {
ShutdownKind::Destroy
} else {
grace_reason
}
}

fn try_finish_grace(&mut self) -> Option<LiveExit> {
let Some(grace) = self.sleep_grace.as_ref() else {
return None;
};
if self.ctx.can_finalize_shutdown(grace.reason) {
let reason = grace.reason;
let reason = self.finalize_shutdown_reason(grace.reason);
self.sleep_grace = None;
return Some(LiveExit::Shutdown { reason });
}
Expand Down Expand Up @@ -1576,7 +1586,7 @@ impl ActorTask {
"actor shutdown reached the grace deadline"
);
Some(LiveExit::Shutdown {
reason: grace.reason,
reason: self.finalize_shutdown_reason(grace.reason),
})
}

Expand Down
Loading