@@ -1801,6 +1801,25 @@ impl ActorTask {
18011801 step = "sync_alarm" ,
18021802 "actor shutdown cleanup step completed"
18031803 ) ;
1804+ // Destroy cancels the engine-side alarm BEFORE the SQLite teardown.
1805+ // `cancel_driver_alarm_logged` issues a `set_alarm(None)` that spawns a
1806+ // last-pushed-alarm SQLite persist; running it here (rather than after
1807+ // `cleanup_sqlite`) lets `wait_for_pending_alarm_writes` below await that
1808+ // persist so it cannot race the teardown and fail with
1809+ // `transaction_closed`. Sleep keeps the persisted engine alarm armed for
1810+ // the next instance, so it only aborts the local timer, after cleanup.
1811+ match reason {
1812+ ShutdownKind :: Destroy => {
1813+ ctx. cancel_driver_alarm_logged ( ) ;
1814+ tracing:: debug!(
1815+ actor_id = %actor_id,
1816+ reason = reason_label,
1817+ step = "cancel_driver_alarm" ,
1818+ "actor shutdown cleanup step completed"
1819+ ) ;
1820+ }
1821+ ShutdownKind :: Sleep => { }
1822+ }
18041823 ctx. wait_for_pending_alarm_writes ( ) . await ;
18051824 tracing:: debug!(
18061825 actor_id = %actor_id,
@@ -1834,15 +1853,7 @@ impl ActorTask {
18341853 "actor shutdown cleanup step completed"
18351854 ) ;
18361855 }
1837- ShutdownKind :: Destroy => {
1838- ctx. cancel_driver_alarm_logged ( ) ;
1839- tracing:: debug!(
1840- actor_id = %actor_id,
1841- reason = reason_label,
1842- step = "cancel_driver_alarm" ,
1843- "actor shutdown cleanup step completed"
1844- ) ;
1845- }
1856+ ShutdownKind :: Destroy => { }
18461857 }
18471858 Ok ( ( ) )
18481859 }
0 commit comments