From eaf461707bfccec5d8d371cd3410d7fe7b053532 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 28 Oct 2023 00:08:40 +0000 Subject: [PATCH] fix(deltachat-rpc-server): always run with at least two threads We already run all async tests with #[tokio::test(flavor = "multi_thread", worker_threads = 2)] as we had problems in the past when running them with one thread. This is a similar change for deltachat-rpc-server that hopefully prevents timeouts of deltachat-rpc-client tests on CI. --- deltachat-rpc-server/Cargo.toml | 1 + deltachat-rpc-server/src/main.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/deltachat-rpc-server/Cargo.toml b/deltachat-rpc-server/Cargo.toml index e1029c749..f81ce07b2 100644 --- a/deltachat-rpc-server/Cargo.toml +++ b/deltachat-rpc-server/Cargo.toml @@ -17,6 +17,7 @@ anyhow = "1" env_logger = { version = "0.10.0" } futures-lite = "2.0.0" log = "0.4" +num_cpus = "1" serde_json = "1.0.105" serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.33.0", features = ["io-std"] } diff --git a/deltachat-rpc-server/src/main.rs b/deltachat-rpc-server/src/main.rs index 4be58760b..a81f27c1d 100644 --- a/deltachat-rpc-server/src/main.rs +++ b/deltachat-rpc-server/src/main.rs @@ -20,9 +20,18 @@ use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use yerpc::{RpcClient, RpcSession}; -#[tokio::main(flavor = "multi_thread")] -async fn main() { - let r = main_impl().await; +fn main() { + // Build multithreaded runtime with at least two threads. + // This ensures that on systems with one CPU + // such as CI runners there are at least two threads + // and it is more difficult to deadlock. + let r = tokio::runtime::Builder::new_multi_thread() + .worker_threads(std::cmp::max(2, num_cpus::get())) + .enable_all() + .build() + .unwrap() + .block_on(main_impl()); + // From tokio documentation: // "For technical reasons, stdin is implemented by using an ordinary blocking read on a separate // thread, and it is impossible to cancel that read. This can make shutdown of the runtime hang