@@ -480,7 +480,7 @@ impl ShutdownManager {
480480 /// - all tracked tasks have terminated
481481 /// - timeout has been reached
482482 /// - shutdown has been forced (by sending SIGINT)
483- async fn finish_shutdown ( mut self ) {
483+ async fn finish_shutdown ( & mut self ) {
484484 let mut wait_futures = FuturesUnordered :: < Pin < Box < dyn Future < Output = ( ) > + Send > > > :: new ( ) ;
485485
486486 // force shutdown via ctrl-c
@@ -496,14 +496,16 @@ impl ShutdownManager {
496496 } ) ) ;
497497
498498 // timeout
499+ let max_shutdown = self . max_shutdown_duration ;
499500 wait_futures. push ( Box :: pin ( async move {
500- sleep ( self . max_shutdown_duration ) . await ;
501+ sleep ( max_shutdown ) . await ;
501502 info ! ( "timeout reached - forcing shutdown" ) ;
502503 } ) ) ;
503504
504505 // graceful
506+ let tracker = self . tracker . clone ( ) ;
505507 wait_futures. push ( Box :: pin ( async move {
506- self . wait_for_tracker ( ) . await ;
508+ tracker . wait_for_tracker ( ) . await ;
507509 info ! ( "all tracked tasks successfully shutdown" ) ;
508510 if let Some ( legacy) = self . legacy_task_manager . as_mut ( ) {
509511 legacy. wait_for_graceful_shutdown ( ) . await ;
@@ -555,15 +557,15 @@ impl ShutdownManager {
555557 /// - all tracked tasks have terminated
556558 /// - timeout has been reached
557559 /// - shutdown has been forced (by sending SIGINT)
558- pub async fn perform_shutdown ( self ) {
560+ pub async fn perform_shutdown ( & mut self ) {
559561 self . send_cancellation ( ) ;
560562
561563 info ! ( "waiting for tasks to finish... (press ctrl-c to force)" ) ;
562564 self . finish_shutdown ( ) . await ;
563565 }
564566
565567 /// Wait until a shutdown signal has been received and trigger system shutdown.
566- pub async fn run_until_shutdown ( mut self ) {
568+ pub async fn run_until_shutdown ( & mut self ) {
567569 self . close_tracker ( ) ;
568570 self . wait_for_shutdown_signal ( ) . await ;
569571
@@ -580,11 +582,11 @@ mod tests {
580582
581583 #[ tokio:: test]
582584 async fn shutdown_with_no_tracked_tasks_and_signals ( ) -> anyhow:: Result < ( ) > {
583- let manager = ShutdownManager :: new_without_signals ( ) ;
585+ let mut manager = ShutdownManager :: new_without_signals ( ) ;
584586 let res = manager. run_until_shutdown ( ) . timeboxed ( ) . await ;
585587 assert ! ( res. has_elapsed( ) ) ;
586588
587- let manager = ShutdownManager :: new_without_signals ( ) ;
589+ let mut manager = ShutdownManager :: new_without_signals ( ) ;
588590 let shutdown = manager. clone_shutdown_token ( ) ;
589591 shutdown. cancel ( ) ;
590592 let res = manager. run_until_shutdown ( ) . timeboxed ( ) . await ;
@@ -596,7 +598,7 @@ mod tests {
596598 #[ tokio:: test]
597599 async fn shutdown_signal ( ) -> anyhow:: Result < ( ) > {
598600 let timeout_shutdown = sleep ( Duration :: from_millis ( 100 ) ) ;
599- let manager = ShutdownManager :: new_without_signals ( ) . with_shutdown ( timeout_shutdown) ;
601+ let mut manager = ShutdownManager :: new_without_signals ( ) . with_shutdown ( timeout_shutdown) ;
600602
601603 // execution finishes after the sleep gets finishes
602604 let res = manager
@@ -610,7 +612,7 @@ mod tests {
610612
611613 #[ tokio:: test]
612614 async fn panic_hook ( ) -> anyhow:: Result < ( ) > {
613- let manager = ShutdownManager :: new_without_signals ( ) . with_cancel_on_panic ( ) ;
615+ let mut manager = ShutdownManager :: new_without_signals ( ) . with_cancel_on_panic ( ) ;
614616 manager. spawn_with_shutdown ( async move {
615617 sleep ( Duration :: from_millis ( 10000 ) ) . await ;
616618 } ) ;
@@ -632,7 +634,7 @@ mod tests {
632634 #[ tokio:: test]
633635 async fn task_cancellation ( ) -> anyhow:: Result < ( ) > {
634636 let timeout_shutdown = sleep ( Duration :: from_millis ( 100 ) ) ;
635- let manager = ShutdownManager :: new_without_signals ( ) . with_shutdown ( timeout_shutdown) ;
637+ let mut manager = ShutdownManager :: new_without_signals ( ) . with_shutdown ( timeout_shutdown) ;
636638
637639 let cancelled1 = Arc :: new ( AtomicBool :: new ( false ) ) ;
638640 let cancelled1_clone = cancelled1. clone ( ) ;
@@ -664,7 +666,7 @@ mod tests {
664666
665667 #[ tokio:: test]
666668 async fn cancellation_within_task ( ) -> anyhow:: Result < ( ) > {
667- let manager = ShutdownManager :: new_without_signals ( ) ;
669+ let mut manager = ShutdownManager :: new_without_signals ( ) ;
668670
669671 let cancelled1 = Arc :: new ( AtomicBool :: new ( false ) ) ;
670672 let cancelled1_clone = cancelled1. clone ( ) ;
@@ -694,7 +696,7 @@ mod tests {
694696 #[ tokio:: test]
695697 async fn shutdown_timeout ( ) -> anyhow:: Result < ( ) > {
696698 let timeout_shutdown = sleep ( Duration :: from_millis ( 50 ) ) ;
697- let manager = ShutdownManager :: new_without_signals ( )
699+ let mut manager = ShutdownManager :: new_without_signals ( )
698700 . with_shutdown ( timeout_shutdown)
699701 . with_shutdown_duration ( Duration :: from_millis ( 1000 ) ) ;
700702
@@ -711,7 +713,7 @@ mod tests {
711713 assert ! ( res. has_elapsed( ) ) ;
712714
713715 let timeout_shutdown = sleep ( Duration :: from_millis ( 50 ) ) ;
714- let manager = ShutdownManager :: new_without_signals ( )
716+ let mut manager = ShutdownManager :: new_without_signals ( )
715717 . with_shutdown ( timeout_shutdown)
716718 . with_shutdown_duration ( Duration :: from_millis ( 100 ) ) ;
717719
0 commit comments