From 9f607ff49843ba1e1751ee39114d465021029262 Mon Sep 17 00:00:00 2001 From: Jeb Bearer Date: Mon, 12 Aug 2024 13:30:10 -0700 Subject: [PATCH] Avoid blocking drop with task cancellation if shut_down is explicitly called --- sequencer/src/context.rs | 11 +++++++---- sequencer/src/external_event_handler.rs | 7 +------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/sequencer/src/context.rs b/sequencer/src/context.rs index a8b6704e84..68caf5f71d 100644 --- a/sequencer/src/context.rs +++ b/sequencer/src/context.rs @@ -168,9 +168,11 @@ impl, P: SequencerPersistence, Ver: StaticVersionTyp let roll_call_info = external_event_handler::RollCallInfo { public_api_url }; // Create the external event handler - let external_event_handler = ExternalEventHandler::new(network, roll_call_info, pub_key) - .await - .with_context(|| "Failed to create external event handler")?; + let mut tasks = TaskList::default(); + let external_event_handler = + ExternalEventHandler::new(&mut tasks, network, roll_call_info, pub_key) + .await + .with_context(|| "Failed to create external event handler")?; Ok(Self::new( handle, @@ -182,7 +184,8 @@ impl, P: SequencerPersistence, Ver: StaticVersionTyp network_config, event_consumer, anchor_view, - )) + ) + .with_task_list(tasks)) } /// Constructor diff --git a/sequencer/src/external_event_handler.rs b/sequencer/src/external_event_handler.rs index 05f7073100..1f930a16ca 100644 --- a/sequencer/src/external_event_handler.rs +++ b/sequencer/src/external_event_handler.rs @@ -40,9 +40,6 @@ pub struct ExternalEventHandler { // The public key of the node pub public_key: BLSPubKey, - // The tasks that are running - pub _tasks: TaskList, - // The outbound message queue pub outbound_message_sender: Sender, } @@ -57,6 +54,7 @@ pub enum OutboundMessage { impl ExternalEventHandler { /// Creates a new `ExternalEventHandler` with the given network and roll call info pub async fn new>( + tasks: &mut TaskList, network: Arc, roll_call_info: RollCallInfo, public_key: BLSPubKey, @@ -65,8 +63,6 @@ impl ExternalEventHandler { let (outbound_message_sender, outbound_message_receiver) = async_compatibility_layer::channel::bounded(10); - let mut tasks: TaskList = Default::default(); - // Spawn the outbound message handling loop tasks.spawn( "ExternalEventHandler (RollCall)", @@ -88,7 +84,6 @@ impl ExternalEventHandler { Ok(Self { roll_call_info, public_key, - _tasks: tasks, outbound_message_sender, }) }