Skip to content

Commit 6d1ba01

Browse files
committed
feat: Make REQUEST_TIMEOUT_SECS and CONNECT configurable
Some kernels can take upwards of 5 minutes to compile but 10 minutes might be too high of a timeout in the most common use cases. Add a runtime configuration option for both the Request and the Connect timeout.
1 parent 6f7e664 commit 6d1ba01

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

docs/Configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ Note that some env variables may need sccache server restart to take effect.
180180
* `SCCACHE_LOG_MILLIS` when set (to any value), enables millisecond precision timestamps in log output instead of the default second precision.
181181
* `SCCACHE_ERROR_LOG` path to a file where sccache will log errors
182182
* `SCCACHE_LOG` log level, accepting standard env_logger values, see [env_logger documentation](https://docs.rs/env_logger/latest/env_logger/#enabling-logging) for details
183+
* `SCCACHE_REQUEST_TIMEOUT_SECS` configurable timeout for requests sent by the Http Client.
184+
* `SCCACHE_CONNECT_TIMEOUT_SECS` configurable timeout for how long a Http Client will try to connect.
183185

184186
### cache configs
185187

src/dist/http.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,9 @@ mod client {
10801080
use flate2::write::ZlibEncoder as ZlibWriteEncoder;
10811081
use futures::TryFutureExt;
10821082
use reqwest::Body;
1083+
use std::cell::LazyCell;
10831084
use std::collections::HashMap;
1085+
use std::env;
10841086
use std::io::Write;
10851087
use std::path::{Path, PathBuf};
10861088
use std::sync::{Arc, Mutex};
@@ -1093,8 +1095,21 @@ mod client {
10931095
use super::urls;
10941096
use crate::errors::*;
10951097

1096-
const REQUEST_TIMEOUT_SECS: u64 = 1200;
1097-
const CONNECT_TIMEOUT_SECS: u64 = 5;
1098+
const REQUEST_TIMEOUT_SECS: LazyCell<Duration> = LazyCell::new(|| {
1099+
let timeout_env: u64 = env::var("SCCACHE_REQUEST_TIMEOUT_SECS")
1100+
.ok()
1101+
.and_then(|value| value.parse::<u64>().ok())
1102+
.unwrap_or(1200);
1103+
Duration::new(timeout_env, 0)
1104+
});
1105+
1106+
const CONNECT_TIMEOUT_SECS: LazyCell<Duration> = LazyCell::new(|| {
1107+
let connect_timeout_env: u64 = env::var("SCCACHE_CONNECT_TIMEOUT_SECS")
1108+
.ok()
1109+
.and_then(|value| value.parse::<u64>().ok())
1110+
.unwrap_or(5);
1111+
Duration::new(connect_timeout_env, 0)
1112+
});
10981113

10991114
pub struct Client {
11001115
auth_token: String,
@@ -1117,11 +1132,9 @@ mod client {
11171132
auth_token: String,
11181133
rewrite_includes_only: bool,
11191134
) -> Result<Self> {
1120-
let timeout = Duration::new(REQUEST_TIMEOUT_SECS, 0);
1121-
let connect_timeout = Duration::new(CONNECT_TIMEOUT_SECS, 0);
11221135
let client = reqwest::ClientBuilder::new()
1123-
.timeout(timeout)
1124-
.connect_timeout(connect_timeout)
1136+
.timeout(*REQUEST_TIMEOUT_SECS)
1137+
.connect_timeout(*CONNECT_TIMEOUT_SECS)
11251138
// Disable connection pool to avoid broken connection
11261139
// between runtime
11271140
.pool_max_idle_per_host(0)
@@ -1159,9 +1172,9 @@ mod client {
11591172
);
11601173
}
11611174
// Finish the client
1162-
let timeout = Duration::new(REQUEST_TIMEOUT_SECS, 0);
11631175
let new_client_async = client_async_builder
1164-
.timeout(timeout)
1176+
.timeout(*REQUEST_TIMEOUT_SECS)
1177+
.connect_timeout(*CONNECT_TIMEOUT_SECS)
11651178
// Disable keep-alive
11661179
.pool_max_idle_per_host(0)
11671180
.build()

0 commit comments

Comments
 (0)