Skip to content

feat(l2): make monitor quit #3622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions cmd/ethrex/l2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use std::{
sync::Arc,
time::Duration,
};
use tokio::sync::Mutex;
use tokio::{sync::Mutex, task::JoinSet};
use tokio_util::task::TaskTracker;
use tracing::{error, info};

Expand Down Expand Up @@ -155,6 +155,7 @@ impl Command {

// TODO: Check every module starts properly.
let tracker = TaskTracker::new();
let mut join_set = JoinSet::new();

let cancel_token = tokio_util::sync::CancellationToken::new();

Expand Down Expand Up @@ -191,7 +192,7 @@ impl Command {
signer,
peer_table.clone(),
store.clone(),
tracker.clone(),
tracker,
blockchain.clone(),
)
.await;
Expand All @@ -217,20 +218,24 @@ impl Command {
)
.into_future();

tracker.spawn(l2_sequencer);
join_set.spawn(l2_sequencer);

tokio::select! {
_ = tokio::signal::ctrl_c() => {
info!("Server shut down started...");
let node_config_path = PathBuf::from(data_dir + "/node_config.json");
info!("Storing config at {:?}...", node_config_path);
cancel_token.cancel();
let node_config = NodeConfigFile::new(peer_table, local_node_record.lock().await.clone()).await;
store_node_config_file(node_config, node_config_path).await;
tokio::time::sleep(Duration::from_secs(1)).await;
info!("Server shutting down!");
join_set.abort_all();
}
_ = join_set.join_next() => {
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When handling the first completed child task via join_set.join_next(), you don’t abort or await the remaining tasks. Explicitly abort pending tasks or await their completion to avoid background leaks.

Copilot uses AI. Check for mistakes.

}
}
info!("Server shut down started...");
let node_config_path = PathBuf::from(data_dir + "/node_config.json");
info!("Storing config at {:?}...", node_config_path);
cancel_token.cancel();
let node_config =
NodeConfigFile::new(peer_table, local_node_record.lock().await.clone()).await;
store_node_config_file(node_config, node_config_path).await;
tokio::time::sleep(Duration::from_secs(1)).await;
info!("Server shutting down!");
}
Self::RemoveDB { datadir, force } => {
Box::pin(async {
Expand Down
13 changes: 8 additions & 5 deletions crates/l2/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,22 @@ pub async fn start_l2(
));
}

while let Some(res) = task_set.join_next().await {
if let Some(res) = task_set.join_next().await {
// If a task finishes, the whole sequencer should stop
match res {
Ok(Ok(_)) => {}
Ok(Err(err)) => {
error!("Error starting Proposer: {err}");
task_set.abort_all();
break;
}
Err(err) => {
error!("JoinSet error: {err}");
task_set.abort_all();
break;
}
};
task_set.abort_all();
} else {
// If no tasks were spawned, we let the sequencer run until it is cancelled
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
}
}
Loading