Skip to content

Commit cf5f369

Browse files
committed
Start tokio runtime after daemonize
1 parent 82f4f1b commit cf5f369

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ dist-client = [
190190
]
191191
# Enables the sccache-dist binary
192192
dist-server = [
193+
"reqwest/blocking",
193194
"jwt",
194195
"flate2",
195196
"libmount",

src/bin/sccache-dist/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::path::Path;
2626
use std::sync::atomic::{AtomicUsize, Ordering};
2727
use std::sync::{Arc, Mutex, MutexGuard};
2828
use std::time::{Duration, Instant};
29+
use tokio::runtime::Runtime;
2930

3031
#[cfg_attr(target_os = "freebsd", path = "build_freebsd.rs")]
3132
mod build;
@@ -40,8 +41,7 @@ pub const INSECURE_DIST_SERVER_TOKEN: &str = "dangerously_insecure_server";
4041
all(target_os = "linux", target_arch = "x86_64"),
4142
target_os = "freebsd"
4243
))]
43-
#[tokio::main]
44-
async fn main() {
44+
fn main() {
4545
init_logging();
4646

4747
let incr_env_strs = ["CARGO_BUILD_INCREMENTAL", "CARGO_INCREMENTAL"];
@@ -69,7 +69,7 @@ async fn main() {
6969
},
7070
};
7171

72-
std::process::exit(match run(command).await {
72+
std::process::exit(match run(command) {
7373
Ok(s) => s,
7474
Err(e) => {
7575
eprintln!("sccache-dist: error: {}", e);
@@ -132,7 +132,7 @@ fn check_jwt_server_token(
132132
.ok()
133133
}
134134

135-
async fn run(command: Command) -> Result<i32> {
135+
fn run(command: Command) -> Result<i32> {
136136
match command {
137137
Command::Auth(AuthSubcommand::Base64 { num_bytes }) => {
138138
let mut bytes = vec![0; num_bytes];
@@ -171,7 +171,6 @@ async fn run(command: Command) -> Result<i32> {
171171
jwks_url,
172172
} => Box::new(
173173
token_check::ValidJWTCheck::new(audience, issuer, &jwks_url)
174-
.await
175174
.context("Failed to create a checker for valid JWTs")?,
176175
),
177176
scheduler_config::ClientAuth::Mozilla { required_groups } => {
@@ -219,7 +218,10 @@ async fn run(command: Command) -> Result<i32> {
219218
check_client_auth,
220219
check_server_auth,
221220
);
222-
http_scheduler.start().await?;
221+
222+
// Create runtime after daemonize because Tokio doesn't work well with daemonize
223+
let runtime = Runtime::new().context("Failed to create Tokio runtime")?;
224+
runtime.block_on(async { http_scheduler.start().await })?;
223225
unreachable!();
224226
}
225227

@@ -296,7 +298,8 @@ async fn run(command: Command) -> Result<i32> {
296298
server,
297299
)
298300
.context("Failed to create sccache HTTP server instance")?;
299-
http_server.start().await?;
301+
let runtime = Runtime::new().context("Failed to create Tokio runtime")?;
302+
runtime.block_on(async { http_server.start().await })?;
300303
unreachable!();
301304
}
302305
}

src/bin/sccache-dist/token_check.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,12 @@ impl ClientAuthCheck for ValidJWTCheck {
339339
}
340340

341341
impl ValidJWTCheck {
342-
pub async fn new(audience: String, issuer: String, jwks_url: &str) -> Result<Self> {
343-
let res = reqwest::get(jwks_url)
344-
.await
345-
.context("Failed to make request to JWKs url")?;
342+
pub fn new(audience: String, issuer: String, jwks_url: &str) -> Result<Self> {
343+
let res = reqwest::blocking::get(jwks_url).context("Failed to make request to JWKs url")?;
346344
if !res.status().is_success() {
347345
bail!("Could not retrieve JWKs, HTTP error: {}", res.status())
348346
}
349-
let jwks: Jwks = res.json().await.context("Failed to parse JWKs json")?;
347+
let jwks: Jwks = res.json().context("Failed to parse JWKs json")?;
350348
let kid_to_pkcs1 = jwks
351349
.keys
352350
.into_iter()

0 commit comments

Comments
 (0)