@@ -570,9 +570,12 @@ impl Actor {
570
570
}
571
571
572
572
trait HashSpecificCommand : HashSpecific + Send + ' static {
573
+ /// Handle the command on success by spawning a task into the per-hash context.
573
574
fn handle ( self , ctx : HashContext ) -> impl Future < Output = ( ) > + Send + ' static ;
574
575
575
- fn on_error ( self ) -> impl Future < Output = ( ) > + Send + ' static ;
576
+ /// Opportunity to send an error if spawning fails due to the task being busy (inbox full)
577
+ /// or dead (e.g. panic in one of the running tasks).
578
+ fn on_error ( self , arg : SpawnArg < EmParams > ) -> impl Future < Output = ( ) > + Send + ' static ;
576
579
577
580
async fn spawn (
578
581
self ,
@@ -581,25 +584,24 @@ trait HashSpecificCommand: HashSpecific + Send + 'static {
581
584
) where
582
585
Self : Sized ,
583
586
{
587
+ let span = tracing:: Span :: current ( ) ;
584
588
let task = manager
585
- . spawn_boxed (
586
- self . hash ( ) ,
587
- Box :: new ( |x| {
588
- Box :: pin ( async move {
589
- match x {
590
- SpawnArg :: Active ( state) => {
591
- self . handle ( state) . await ;
592
- }
593
- SpawnArg :: Busy => {
594
- self . on_error ( ) . await ;
595
- }
596
- SpawnArg :: Dead => {
597
- self . on_error ( ) . await ;
598
- }
589
+ . spawn ( self . hash ( ) , |arg| {
590
+ async move {
591
+ match arg {
592
+ SpawnArg :: Active ( state) => {
593
+ self . handle ( state) . await ;
599
594
}
600
- } )
601
- } ) ,
602
- )
595
+ SpawnArg :: Busy => {
596
+ self . on_error ( arg) . await ;
597
+ }
598
+ SpawnArg :: Dead => {
599
+ self . on_error ( arg) . await ;
600
+ }
601
+ }
602
+ }
603
+ . instrument ( span)
604
+ } )
603
605
. await ;
604
606
if let Some ( task) = task {
605
607
tasks. spawn ( task) ;
@@ -611,31 +613,31 @@ impl HashSpecificCommand for ObserveMsg {
611
613
async fn handle ( self , ctx : HashContext ) {
612
614
observe ( self , ctx) . await
613
615
}
614
- async fn on_error ( self ) { }
616
+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
615
617
}
616
618
impl HashSpecificCommand for ExportPathMsg {
617
619
async fn handle ( self , ctx : HashContext ) {
618
620
export_path ( self , ctx) . await
619
621
}
620
- async fn on_error ( self ) { }
622
+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
621
623
}
622
624
impl HashSpecificCommand for ExportBaoMsg {
623
625
async fn handle ( self , ctx : HashContext ) {
624
626
export_bao ( self , ctx) . await
625
627
}
626
- async fn on_error ( self ) { }
628
+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
627
629
}
628
630
impl HashSpecificCommand for ExportRangesMsg {
629
631
async fn handle ( self , ctx : HashContext ) {
630
632
export_ranges ( self , ctx) . await
631
633
}
632
- async fn on_error ( self ) { }
634
+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
633
635
}
634
636
impl HashSpecificCommand for ImportBaoMsg {
635
637
async fn handle ( self , ctx : HashContext ) {
636
638
import_bao ( self , ctx) . await
637
639
}
638
- async fn on_error ( self ) { }
640
+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
639
641
}
640
642
impl HashSpecific for ( TempTag , ImportEntryMsg ) {
641
643
fn hash ( & self ) -> Hash {
@@ -647,7 +649,7 @@ impl HashSpecificCommand for (TempTag, ImportEntryMsg) {
647
649
let ( tt, cmd) = self ;
648
650
finish_import ( cmd, tt, ctx) . await
649
651
}
650
- async fn on_error ( self ) { }
652
+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
651
653
}
652
654
653
655
struct RtWrapper ( Option < tokio:: runtime:: Runtime > ) ;
0 commit comments