Skip to content

Commit 08dd678

Browse files
just-an-engineerjust-an-engineer
authored andcommitted
Add ability to specify server timeout amount in ms from config file
1 parent 3a25652 commit 08dd678

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub fn run_command(cmd: Command) -> Result<i32> {
631631
// Config isn't required for all commands, but if it's broken then we should flag
632632
// it early and loudly.
633633
let config = &Config::load()?;
634-
let startup_timeout = config.server_startup_timeout;
634+
let startup_timeout = config.server_timing.startup_timeout;
635635

636636
match cmd {
637637
Command::ShowStats(fmt, advanced) => {

src/config.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,18 @@ impl Default for DistConfig {
555555
pub struct FileConfig {
556556
pub cache: CacheConfigs,
557557
pub dist: DistConfig,
558+
// pub timing: ServerTimingConfig,
558559
pub server_startup_timeout_ms: Option<u64>,
560+
pub server_shutdown_timeout_ms: Option<u64>,
559561
pub port: Option<u16>,
560562
}
561563

564+
// #[derive(Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
565+
// pub struct ServerTimingConfig {
566+
// pub server_startup_timeout_ms: Option<u64>,
567+
// pub server_shutdown_timeout_ms: Option<u64>,
568+
// }
569+
562570
// If the file doesn't exist or we can't read it, log the issue and proceed. If the
563571
// config exists but doesn't parse then something is wrong - return an error.
564572
pub fn try_read_config_file<T: DeserializeOwned>(path: &Path) -> Result<Option<T>> {
@@ -946,10 +954,16 @@ pub struct Config {
946954
pub cache: Option<CacheType>,
947955
pub fallback_cache: DiskCacheConfig,
948956
pub dist: DistConfig,
949-
pub server_startup_timeout: Option<std::time::Duration>,
957+
pub server_timing: ServerTiming,
950958
pub port: Option<u16>,
951959
}
952960

961+
#[derive(Debug, Default, PartialEq, Eq)]
962+
pub struct ServerTiming {
963+
pub startup_timeout: Option<std::time::Duration>,
964+
pub shutdown_timeout: Option<std::time::Duration>,
965+
}
966+
953967
impl Config {
954968
pub fn load() -> Result<Self> {
955969
let env_conf = config_from_env()?;
@@ -969,12 +983,20 @@ impl Config {
969983
cache,
970984
dist,
971985
server_startup_timeout_ms,
986+
server_shutdown_timeout_ms,
972987
port,
973988
} = file_conf;
974989
conf_caches.merge(cache);
975990

976991
let server_startup_timeout =
977992
server_startup_timeout_ms.map(std::time::Duration::from_millis);
993+
let server_shutdown_timeout =
994+
server_shutdown_timeout_ms.map(std::time::Duration::from_millis);
995+
let server_timing = ServerTiming {
996+
startup_timeout: server_startup_timeout,
997+
shutdown_timeout: server_shutdown_timeout,
998+
};
999+
9781000

9791001
let EnvConfig { cache } = env_conf;
9801002
conf_caches.merge(cache);
@@ -984,7 +1006,7 @@ impl Config {
9841006
cache: caches,
9851007
fallback_cache,
9861008
dist,
987-
server_startup_timeout,
1009+
server_timing,
9881010
port,
9891011
}
9901012
}
@@ -1285,6 +1307,7 @@ fn config_overrides() {
12851307
},
12861308
dist: Default::default(),
12871309
server_startup_timeout_ms: None,
1310+
server_shutdown_timeout_ms: None,
12881311
port: None,
12891312
};
12901313

@@ -1307,7 +1330,7 @@ fn config_overrides() {
13071330
rw_mode: CacheModeConfig::ReadWrite,
13081331
},
13091332
dist: Default::default(),
1310-
server_startup_timeout: None,
1333+
server_timing: Default::default(),
13111334
port: None,
13121335
}
13131336
);
@@ -1583,7 +1606,8 @@ no_credentials = true
15831606
toolchain_cache_size: 5368709120,
15841607
rewrite_includes_only: false,
15851608
},
1586-
server_startup_timeout_ms: Some(10000),
1609+
server_startup_timeout_ms: Some(10_000),
1610+
server_shutdown_timeout_ms: None,
15871611
port: None,
15881612
}
15891613
)
@@ -1600,6 +1624,7 @@ fn test_port_config() {
16001624
cache: Default::default(),
16011625
dist: Default::default(),
16021626
server_startup_timeout_ms: None,
1627+
server_shutdown_timeout_ms: None,
16031628
port: Some(8080),
16041629
}
16051630
)

src/server.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,12 @@ impl<C: CommandCreatorSync> SccacheServer<C> {
658658
}
659659
})?;
660660

661-
const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(10);
661+
let config = Config::load().unwrap_or_default();
662+
let shutdown_timeout: Duration = config.server_timing.shutdown_timeout.unwrap_or(Duration::from_secs(10));
662663
info!(
663664
"moving into the shutdown phase now, waiting at most {} seconds \
664665
for all client requests to complete",
665-
SHUTDOWN_TIMEOUT.as_secs()
666+
shutdown_timeout.as_secs()
666667
);
667668

668669
// Once our server has shut down either due to inactivity or a manual
@@ -672,7 +673,7 @@ impl<C: CommandCreatorSync> SccacheServer<C> {
672673
//
673674
// Note that we cap the amount of time this can take, however, as we
674675
// don't want to wait *too* long.
675-
runtime.block_on(async { time::timeout(SHUTDOWN_TIMEOUT, wait).await })?;
676+
runtime.block_on(async { time::timeout(shutdown_timeout, wait).await })?;
676677

677678
info!("ok, fully shutting down now");
678679

tests/harness/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub fn sccache_client_cfg(
165165
rewrite_includes_only: false, // TODO
166166
},
167167
server_startup_timeout_ms: None,
168+
server_shutdown_timeout_ms: None,
168169
port: None,
169170
}
170171
}

tests/oauth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn config_with_dist_auth(
6060
rewrite_includes_only: true,
6161
},
6262
server_startup_timeout_ms: None,
63+
server_shutdown_timeout_ms: None,
6364
port: None,
6465
}
6566
}

0 commit comments

Comments
 (0)