From ad5d853fe6569996a98d53140b4d5cdc06753a5d Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Wed, 28 Aug 2024 18:30:16 +0300 Subject: [PATCH] Don't rely on tokio_unstable config flag Tokio does not guarantee semver stability of unstable features, so it's a bad idea to use this flag. It's also annoying to have to override rustflags everywhere. --- .cargo/config.toml | 6 ++---- crates/aptos-runtimes/src/lib.rs | 1 - crates/aptos/src/node/local_testnet/mod.rs | 20 +++++++++----------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 189584de8e2e2..a7c9417b5a881 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -15,17 +15,15 @@ xclippy = [ x = "run --package aptos-cargo-cli --bin aptos-cargo-cli --" [build] -rustflags = ["--cfg", "tokio_unstable", "-C", "force-frame-pointers=yes", "-C", "force-unwind-tables=yes"] +rustflags = ["-C", "force-frame-pointers=yes", "-C", "force-unwind-tables=yes"] # TODO(grao): Figure out whether we should enable othaer cpu features, and whether we should use a different way to configure them rather than list every single one here. [target.x86_64-unknown-linux-gnu] -rustflags = ["--cfg", "tokio_unstable", "-C", "link-arg=-fuse-ld=lld", "-C", "force-frame-pointers=yes", "-C", "force-unwind-tables=yes", "-C", "target-feature=+sse4.2"] +rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "force-frame-pointers=yes", "-C", "force-unwind-tables=yes", "-C", "target-feature=+sse4.2"] # 64 bit MSVC [target.x86_64-pc-windows-msvc] rustflags = [ - "--cfg", - "tokio_unstable", "-C", "force-frame-pointers=yes", "-C", diff --git a/crates/aptos-runtimes/src/lib.rs b/crates/aptos-runtimes/src/lib.rs index 74a16ca7aca1e..eb753903542b1 100644 --- a/crates/aptos-runtimes/src/lib.rs +++ b/crates/aptos-runtimes/src/lib.rs @@ -44,7 +44,6 @@ where format!("{}-{}", thread_name_clone, id) }) .on_thread_start(on_thread_start) - .disable_lifo_slot() // Limit concurrent blocking tasks from spawn_blocking(), in case, for example, too many // Rest API calls overwhelm the node. .max_blocking_threads(MAX_BLOCKING_THREADS) diff --git a/crates/aptos/src/node/local_testnet/mod.rs b/crates/aptos/src/node/local_testnet/mod.rs index cf1a308137035..9b99b267ff2e9 100644 --- a/crates/aptos/src/node/local_testnet/mod.rs +++ b/crates/aptos/src/node/local_testnet/mod.rs @@ -352,10 +352,14 @@ impl CliCommand<()> for RunLocalnet { .collect(); let mut join_set = JoinSet::new(); + let mut task_id = 0usize; // Start each of the services. for manager in managers.into_iter() { - join_set.spawn(manager.run()); + task_id += 1; + join_set.spawn(async move { + manager.run().await.map(|()| task_id) + }); } // Wait for all the services to start up. While doing so we also wait for any @@ -398,29 +402,23 @@ impl CliCommand<()> for RunLocalnet { // see `ShutdownStep` for more info. In particular, to speak to how "best effort" // this really is, to make sure ctrl-c happens more or less instantly, we only // register this handler after all the services have started. - let abort_handle = join_set.spawn(async move { + join_set.spawn(async move { tokio::signal::ctrl_c() .await .expect("Failed to register ctrl-c hook"); - Ok(()) + Ok(0) }); - let ctrl_c_task_id = abort_handle.id(); // Wait for one of the tasks to end. We should never get past this point unless // something goes goes wrong or the user signals for the process to end. We // unwrap once because we know for certain the set is not empty and that's the // only condition in which this can return `None`. - let result = join_set.join_next_with_id().await.unwrap(); + let result = join_set.join_next().await.unwrap(); // We want to print a different message depending on which task ended. We can // determine if the task that ended was the ctrl-c task based on the ID of the // task. - let finished_task_id = match &result { - Ok((id, _)) => *id, - Err(err) => err.id(), - }; - - let was_ctrl_c = finished_task_id == ctrl_c_task_id; + let was_ctrl_c = matches!(result, Ok(Ok(id)) if id == 0); if was_ctrl_c { eprintln!("\nReceived ctrl-c, running shutdown steps..."); } else {