@@ -570,9 +570,12 @@ impl Actor {
570570}
571571
572572trait HashSpecificCommand : HashSpecific + Send + ' static {
573+ /// Handle the command on success by spawning a task into the per-hash context.
573574 fn handle ( self , ctx : HashContext ) -> impl Future < Output = ( ) > + Send + ' static ;
574575
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 ;
576579
577580 async fn spawn (
578581 self ,
@@ -581,25 +584,24 @@ trait HashSpecificCommand: HashSpecific + Send + 'static {
581584 ) where
582585 Self : Sized ,
583586 {
587+ let span = tracing:: Span :: current ( ) ;
584588 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 ;
599594 }
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+ } )
603605 . await ;
604606 if let Some ( task) = task {
605607 tasks. spawn ( task) ;
@@ -611,31 +613,31 @@ impl HashSpecificCommand for ObserveMsg {
611613 async fn handle ( self , ctx : HashContext ) {
612614 observe ( self , ctx) . await
613615 }
614- async fn on_error ( self ) { }
616+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
615617}
616618impl HashSpecificCommand for ExportPathMsg {
617619 async fn handle ( self , ctx : HashContext ) {
618620 export_path ( self , ctx) . await
619621 }
620- async fn on_error ( self ) { }
622+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
621623}
622624impl HashSpecificCommand for ExportBaoMsg {
623625 async fn handle ( self , ctx : HashContext ) {
624626 export_bao ( self , ctx) . await
625627 }
626- async fn on_error ( self ) { }
628+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
627629}
628630impl HashSpecificCommand for ExportRangesMsg {
629631 async fn handle ( self , ctx : HashContext ) {
630632 export_ranges ( self , ctx) . await
631633 }
632- async fn on_error ( self ) { }
634+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
633635}
634636impl HashSpecificCommand for ImportBaoMsg {
635637 async fn handle ( self , ctx : HashContext ) {
636638 import_bao ( self , ctx) . await
637639 }
638- async fn on_error ( self ) { }
640+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
639641}
640642impl HashSpecific for ( TempTag , ImportEntryMsg ) {
641643 fn hash ( & self ) -> Hash {
@@ -647,7 +649,7 @@ impl HashSpecificCommand for (TempTag, ImportEntryMsg) {
647649 let ( tt, cmd) = self ;
648650 finish_import ( cmd, tt, ctx) . await
649651 }
650- async fn on_error ( self ) { }
652+ async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
651653}
652654
653655struct RtWrapper ( Option < tokio:: runtime:: Runtime > ) ;
0 commit comments