Skip to content

Commit

Permalink
make CTRL-C handling extra-graceful (2-stage spam termination)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroXbrock committed Dec 12, 2024
1 parent dec538e commit 461a138
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/core/src/spammer/spammer_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ where

let quit_clone = quit.clone();
tokio::task::spawn(async move {
let _ = tokio::signal::ctrl_c().await;
let mut quit = quit_clone.lock().unwrap();
*quit = true;
loop {
let _ = tokio::signal::ctrl_c().await;
let mut quit = quit_clone.lock().unwrap();
*quit = true;
}
});

async move {
Expand All @@ -67,6 +69,13 @@ where
let mut cursor = self.on_spam(scenario).await?.take(num_periods);

while let Some(trigger) = cursor.next().await {
if *quit.lock().expect("lock failure") {
println!("CTRL-C received, stopping spam and collecting results...");
let mut quit = quit.lock().expect("lock failure");
*quit = false;
break;
}

let trigger = trigger.to_owned();
let payloads = scenario.prepare_spam(tx_req_chunks[tick]).await?;
let spam_tasks = scenario
Expand All @@ -93,12 +102,12 @@ where
break;
}
if *quit.lock().expect("lock failure") {
println!("CTRL-C received, stopping spam...");
println!("CTRL-C received, stopping result collection...");
break;
}
block_counter += 1;
}
println!("done spamming. run_id={}", run_id);
println!("done. run_id={}", run_id);
}

Ok(())
Expand Down

0 comments on commit 461a138

Please sign in to comment.