From 46f467561161ebeac99b887cee5e13f0f844fa80 Mon Sep 17 00:00:00 2001 From: ABCxFF <79597906+abcxff@users.noreply.github.com> Date: Fri, 31 Jul 2026 05:20:23 +0000 Subject: [PATCH] fix(rivetkit-core): honor ctx.destroy() requested during a sleep grace --- .../packages/rivetkit-core/src/actor/task.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs index c71358969d..4038629987 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs @@ -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 { 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 }); } @@ -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), }) }