1818 thread:: JoinHandle ,
1919 time:: Duration ,
2020 } ,
21+ tokio_util:: sync:: CancellationToken ,
2122} ;
2223
2324pub struct BankingPacketReceivers {
@@ -29,6 +30,7 @@ pub struct BankingPacketReceivers {
2930/// Spawns a thread to receive packets from TPU and send them to the external scheduler.
3031pub fn spawn (
3132 exit : Arc < AtomicBool > ,
33+ shutdown_signal : CancellationToken ,
3234 receivers : BankingPacketReceivers ,
3335 AgaveTpuToPackSession {
3436 allocator,
@@ -38,13 +40,14 @@ pub fn spawn(
3840 std:: thread:: Builder :: new ( )
3941 . name ( "solTpu2Pack" . to_string ( ) )
4042 . spawn ( move || {
41- tpu_to_pack ( exit, receivers, allocator, producer) ;
43+ tpu_to_pack ( exit, shutdown_signal , receivers, allocator, producer) ;
4244 } )
4345 . unwrap ( )
4446}
4547
4648fn tpu_to_pack (
4749 exit : Arc < AtomicBool > ,
50+ shutdown_signal : CancellationToken ,
4851 receivers : BankingPacketReceivers ,
4952 allocator : Allocator ,
5053 mut producer : shaq:: Producer < TpuToPackMessage > ,
@@ -68,7 +71,9 @@ fn tpu_to_pack(
6871 } {
6972 Ok ( packet_batches) => packet_batches,
7073 Err ( crossbeam_channel:: RecvError ) => {
71- // Senders have been dropped, exit the loop.
74+ // Senders have been dropped, signal shutdown and exit.
75+ shutdown_signal. cancel ( ) ;
76+
7277 break ;
7378 }
7479 } ;
0 commit comments