@@ -26,6 +26,7 @@ use std::path::Path;
26
26
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
27
27
use std:: sync:: { Arc , Mutex , MutexGuard } ;
28
28
use std:: time:: { Duration , Instant } ;
29
+ use tokio:: runtime:: Runtime ;
29
30
30
31
#[ cfg_attr( target_os = "freebsd" , path = "build_freebsd.rs" ) ]
31
32
mod build;
@@ -40,8 +41,7 @@ pub const INSECURE_DIST_SERVER_TOKEN: &str = "dangerously_insecure_server";
40
41
all( target_os = "linux" , target_arch = "x86_64" ) ,
41
42
target_os = "freebsd"
42
43
) ) ]
43
- #[ tokio:: main]
44
- async fn main ( ) {
44
+ fn main ( ) {
45
45
init_logging ( ) ;
46
46
47
47
let incr_env_strs = [ "CARGO_BUILD_INCREMENTAL" , "CARGO_INCREMENTAL" ] ;
@@ -69,7 +69,7 @@ async fn main() {
69
69
} ,
70
70
} ;
71
71
72
- std:: process:: exit ( match run ( command) . await {
72
+ std:: process:: exit ( match run ( command) {
73
73
Ok ( s) => s,
74
74
Err ( e) => {
75
75
eprintln ! ( "sccache-dist: error: {}" , e) ;
@@ -132,7 +132,7 @@ fn check_jwt_server_token(
132
132
. ok ( )
133
133
}
134
134
135
- async fn run ( command : Command ) -> Result < i32 > {
135
+ fn run ( command : Command ) -> Result < i32 > {
136
136
match command {
137
137
Command :: Auth ( AuthSubcommand :: Base64 { num_bytes } ) => {
138
138
let mut bytes = vec ! [ 0 ; num_bytes] ;
@@ -171,7 +171,6 @@ async fn run(command: Command) -> Result<i32> {
171
171
jwks_url,
172
172
} => Box :: new (
173
173
token_check:: ValidJWTCheck :: new ( audience, issuer, & jwks_url)
174
- . await
175
174
. context ( "Failed to create a checker for valid JWTs" ) ?,
176
175
) ,
177
176
scheduler_config:: ClientAuth :: Mozilla { required_groups } => {
@@ -219,7 +218,10 @@ async fn run(command: Command) -> Result<i32> {
219
218
check_client_auth,
220
219
check_server_auth,
221
220
) ;
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 } ) ?;
223
225
unreachable ! ( ) ;
224
226
}
225
227
@@ -296,7 +298,8 @@ async fn run(command: Command) -> Result<i32> {
296
298
server,
297
299
)
298
300
. 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 } ) ?;
300
303
unreachable ! ( ) ;
301
304
}
302
305
}
0 commit comments