Skip to content

Use oxide-tokio-rt rather than #[tokio::main] #80

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
71 changes: 55 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ libc = "0.2"
mockall = "0.13.1"
omicron-zone-package = "0.12"
openssl = "0.10"
oxide-tokio-rt = "0.1.2"
parking_lot = "0.12"
pretty_assertions = "1.4"
proc-macro2 = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[disallowed-macros]]
path = "tokio::main"
reason = "prefer `oxide_tokio_rt` for production software"
replacement = "oxide_tokio_rt::run"
1 change: 1 addition & 0 deletions dpd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal-dns-resolver.workspace = true
internal-dns-types.workspace = true
nexus-client.workspace = true
omicron-common.workspace = true
oxide-tokio-rt.workspace = true
oximeter.workspace = true
oximeter-producer.workspace = true
smf.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions dpd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,12 @@ async fn sidecar_main(mut switch: Switch) -> anyhow::Result<()> {
Ok(())
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
let args = Args::from_args();

match args {
Args::Openapi => print_openapi(),
Args::Run(opt) => run_dpd(opt).await,
Args::Run(opt) => oxide_tokio_rt::run(run_dpd(opt)),
}
}

Expand Down
1 change: 1 addition & 0 deletions swadm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ colored.workspace = true
common.workspace = true
dpd-client.workspace = true
futures.workspace = true
oxide-tokio-rt.workspace = true
oxnet.workspace = true
slog.workspace = true
structopt.workspace = true
Expand Down
10 changes: 8 additions & 2 deletions swadm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ async fn build_info(client: &Client) -> anyhow::Result<()> {
Ok(())
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
oxide_tokio_rt::run_builder(
&mut oxide_tokio_rt::Builder::new_current_thread(),
main_impl(),
)
}

async fn main_impl() -> anyhow::Result<()> {
let opts = GlobalOpts::from_args();
let port = opts.port.unwrap_or_else(default_port);
let host = opts.host.unwrap_or_else(|| "localhost".to_string());
Expand Down
1 change: 1 addition & 0 deletions tfportd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tokio.workspace = true
uuid.workspace = true

omicron-common.workspace = true
oxide-tokio-rt.workspace = true
oximeter.workspace = true
oximeter-instruments.workspace = true
oximeter-producer.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions tfportd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ fn pcap_open(log: &slog::Logger, pkt_src: &str) -> anyhow::Result<pcap::Pcap> {
Ok(pcap)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
oxide_tokio_rt::run(main_impl())
}

async fn main_impl() -> anyhow::Result<()> {
let opts = Opt::from_args();
let config = config::build_config(&opts)?;

Expand Down
1 change: 1 addition & 0 deletions uplinkd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ common.workspace = true

anyhow.workspace = true
libc.workspace = true
oxide-tokio-rt.workspace = true
oxnet.workspace = true
signal-hook.workspace = true
slog.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions uplinkd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,11 @@ fn handle_signals(log: slog::Logger, tx: mpsc::Sender<Messages>) {
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
oxide_tokio_rt::run(main_impl())
}

async fn main_impl() -> anyhow::Result<()> {
let opts = Opt::from_args();

let mut global = Global {
Expand Down
5 changes: 5 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ fn collect_binaries<T: ToString>(
collect(src, dst, binaries)
}

#[expect(
clippy::disallowed_macros,
reason = "using `#[tokio::main]` in xtasks is fine, as they are not \
deployed in production"
)]
#[tokio::main]
async fn main() {
let task = Xtasks::from_args();
Expand Down