Skip to content

Commit

Permalink
Avoid blocking drop with task cancellation if shut_down is explicitly…
Browse files Browse the repository at this point in the history
… called
  • Loading branch information
jbearer committed Aug 15, 2024
1 parent 21622f4 commit 9f607ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 7 additions & 4 deletions sequencer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ impl<N: ConnectedNetwork<PubKey>, 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,
Expand All @@ -182,7 +184,8 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, Ver: StaticVersionTyp
network_config,
event_consumer,
anchor_view,
))
)
.with_task_list(tasks))
}

/// Constructor
Expand Down
7 changes: 1 addition & 6 deletions sequencer/src/external_event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OutboundMessage>,
}
Expand All @@ -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<N: ConnectedNetwork<PubKey>>(
tasks: &mut TaskList,
network: Arc<N>,
roll_call_info: RollCallInfo,
public_key: BLSPubKey,
Expand All @@ -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)",
Expand All @@ -88,7 +84,6 @@ impl ExternalEventHandler {
Ok(Self {
roll_call_info,
public_key,
_tasks: tasks,
outbound_message_sender,
})
}
Expand Down

0 comments on commit 9f607ff

Please sign in to comment.