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