44use super :: mix_traffic:: ClientRequestSender ;
55use super :: received_buffer:: ReceivedBufferMessage ;
66use super :: statistics_control:: StatisticsControl ;
7- use crate :: client:: base_client:: helpers:: ShutdownHelper ;
87use crate :: client:: base_client:: storage:: helpers:: store_client_keys;
98use crate :: client:: base_client:: storage:: MixnetClientStorage ;
109use crate :: client:: cover_traffic_stream:: LoopCoverTrafficStream ;
@@ -53,7 +52,7 @@ use nym_sphinx::receiver::{ReconstructedMessage, SphinxMessageReceiver};
5352use nym_statistics_common:: clients:: ClientStatsSender ;
5453use nym_statistics_common:: generate_client_stats_id;
5554use nym_task:: connections:: { ConnectionCommandReceiver , ConnectionCommandSender , LaneQueueLengths } ;
56- use nym_task:: { ShutdownManager , ShutdownTracker } ;
55+ use nym_task:: ShutdownTracker ;
5756use nym_topology:: provider_trait:: TopologyProvider ;
5857use nym_topology:: HardcodedTopologyProvider ;
5958use nym_validator_client:: nym_api:: NymApiClientExt ;
@@ -881,8 +880,12 @@ where
881880 let shared_topology_accessor =
882881 TopologyAccessor :: new ( self . config . debug . topology . ignore_egress_epoch_role ) ;
883882
884- // Shutdown notifier for signalling tasks to stop
885- let shutdown = ShutdownHelper :: new ( self . shutdown ) ?;
883+ // Create a shutdown tracker for this client - either as a child of provided tracker
884+ // or get one from the registry
885+ let shutdown_tracker = match self . shutdown {
886+ Some ( parent_tracker) => parent_tracker. child_tracker ( ) ,
887+ None => nym_task:: get_sdk_shutdown_tracker ( ) ?,
888+ } ;
886889
887890 // channels responsible for dealing with reply-related fun
888891 let ( reply_controller_sender, reply_controller_receiver) =
@@ -914,7 +917,7 @@ where
914917 self . user_agent . clone ( ) ,
915918 generate_client_stats_id ( * self_address. identity ( ) ) ,
916919 input_sender. clone ( ) ,
917- shutdown . tracker ( ) ,
920+ & shutdown_tracker . child_tracker ( ) ,
918921 ) ;
919922
920923 // needs to be started as the first thing to block if required waiting for the gateway
@@ -924,14 +927,14 @@ where
924927 shared_topology_accessor. clone ( ) ,
925928 self_address. gateway ( ) ,
926929 self . wait_for_gateway ,
927- shutdown . tracker ( ) ,
930+ & shutdown_tracker . child_tracker ( ) ,
928931 )
929932 . await ?;
930933
931934 let gateway_packet_router = PacketRouter :: new (
932935 ack_sender,
933936 mixnet_messages_sender,
934- shutdown . shutdown_token ( ) ,
937+ shutdown_tracker . clone_shutdown_token ( ) ,
935938 ) ;
936939
937940 let gateway_transceiver = Self :: setup_gateway_transceiver (
@@ -944,15 +947,15 @@ where
944947 stats_reporter. clone ( ) ,
945948 #[ cfg( unix) ]
946949 self . connection_fd_callback ,
947- shutdown . tracker ( ) ,
950+ & shutdown_tracker . child_tracker ( ) ,
948951 )
949952 . await ?;
950953 let gateway_ws_fd = gateway_transceiver. ws_fd ( ) ;
951954
952955 let reply_storage = Self :: setup_persistent_reply_storage (
953956 reply_storage_backend,
954957 key_rotation_config,
955- shutdown . tracker ( ) ,
958+ & shutdown_tracker . child_tracker ( ) ,
956959 )
957960 . await ?;
958961
@@ -963,16 +966,18 @@ where
963966 reply_storage. key_storage ( ) ,
964967 reply_controller_sender. clone ( ) ,
965968 stats_reporter. clone ( ) ,
966- shutdown . tracker ( ) ,
969+ & shutdown_tracker . child_tracker ( ) ,
967970 ) ;
968971
969972 // The message_sender is the transmitter for any component generating sphinx packets
970973 // that are to be sent to the mixnet. They are used by cover traffic stream and real
971974 // traffic stream.
972975 // The MixTrafficController then sends the actual traffic
973976
974- let ( message_sender, client_request_sender) =
975- Self :: start_mix_traffic_controller ( gateway_transceiver, shutdown. tracker ( ) ) ;
977+ let ( message_sender, client_request_sender) = Self :: start_mix_traffic_controller (
978+ gateway_transceiver,
979+ & shutdown_tracker. child_tracker ( ) ,
980+ ) ;
976981
977982 // Channels that the websocket listener can use to signal downstream to the real traffic
978983 // controller that connections are closed.
@@ -1001,7 +1006,7 @@ where
10011006 shared_lane_queue_lengths. clone ( ) ,
10021007 client_connection_rx,
10031008 stats_reporter. clone ( ) ,
1004- shutdown . tracker ( ) ,
1009+ & shutdown_tracker . child_tracker ( ) ,
10051010 ) ;
10061011
10071012 if !self
@@ -1017,7 +1022,7 @@ where
10171022 shared_topology_accessor. clone ( ) ,
10181023 message_sender,
10191024 stats_reporter. clone ( ) ,
1020- shutdown . tracker ( ) ,
1025+ & shutdown_tracker . child_tracker ( ) ,
10211026 ) ;
10221027 }
10231028
@@ -1045,7 +1050,7 @@ where
10451050 gateway_connection : GatewayConnection { gateway_ws_fd } ,
10461051 } ,
10471052 stats_reporter,
1048- shutdown_handle : shutdown . into_internal ( ) ,
1053+ shutdown_handle : Some ( shutdown_tracker ) , // The primary tracker for this client
10491054 client_request_sender,
10501055 forget_me : self . config . debug . forget_me ,
10511056 remember_me : self . config . debug . remember_me ,
@@ -1061,7 +1066,7 @@ pub struct BaseClient {
10611066 pub client_state : ClientState ,
10621067 pub stats_reporter : ClientStatsSender ,
10631068 pub client_request_sender : ClientRequestSender ,
1064- pub shutdown_handle : Option < ShutdownManager > ,
1069+ pub shutdown_handle : Option < ShutdownTracker > ,
10651070 pub forget_me : ForgetMe ,
10661071 pub remember_me : RememberMe ,
10671072}
0 commit comments