Commit f3bbc6ad9f

f3bbc6ad9fe0e519f92944f9da22a90532cc5d11

parent: 2dd8c0fddf

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-03-12 22:43 UTC

Support configuring client request timeout (#54)

Layout: unified · split

src/config.rs +6
@@ -25,6 +25,8 @@ macro_rules! usage {
2525 }
2626}
2727
28const DEFAULT_REQ_TIMEOUT: u64 = 120;
29
2830const COLORS: [Color; 13] = [
2931 Color::Blue,
3032 Color::Cyan,
@@ -182,6 +184,7 @@ pub struct TunableValues {
182184 pub reaction_shortcode_display: bool,
183185 pub read_receipt_send: bool,
184186 pub read_receipt_display: bool,
187 pub request_timeout: u64,
185188 pub typing_notice_send: bool,
186189 pub typing_notice_display: bool,
187190 pub users: UserOverrides,
@@ -194,6 +197,7 @@ pub struct Tunables {
194197 pub reaction_shortcode_display: Option<bool>,
195198 pub read_receipt_send: Option<bool>,
196199 pub read_receipt_display: Option<bool>,
200 pub request_timeout: Option<u64>,
197201 pub typing_notice_send: Option<bool>,
198202 pub typing_notice_display: Option<bool>,
199203 pub users: Option<UserOverrides>,
@@ -209,6 +213,7 @@ impl Tunables {
209213 .or(other.reaction_shortcode_display),
210214 read_receipt_send: self.read_receipt_send.or(other.read_receipt_send),
211215 read_receipt_display: self.read_receipt_display.or(other.read_receipt_display),
216 request_timeout: self.request_timeout.or(other.request_timeout),
212217 typing_notice_send: self.typing_notice_send.or(other.typing_notice_send),
213218 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
214219 users: merge_users(self.users, other.users),
@@ -222,6 +227,7 @@ impl Tunables {
222227 reaction_shortcode_display: self.reaction_shortcode_display.unwrap_or(false),
223228 read_receipt_send: self.read_receipt_send.unwrap_or(true),
224229 read_receipt_display: self.read_receipt_display.unwrap_or(true),
230 request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT),
225231 typing_notice_send: self.typing_notice_send.unwrap_or(true),
226232 typing_notice_display: self.typing_notice_display.unwrap_or(true),
227233 users: self.users.unwrap_or_default(),
src/tests.rs +1
@@ -174,6 +174,7 @@ pub fn mock_tunables() -> TunableValues {
174174 reaction_shortcode_display: false,
175175 read_receipt_send: true,
176176 read_receipt_display: true,
177 request_timeout: 120,
177178 typing_notice_send: true,
178179 typing_notice_display: true,
179180 users: vec![(TEST_USER5.clone(), UserDisplayTunables {
src/worker.rs +7 −8
@@ -82,7 +82,6 @@ use crate::{
8282
8383const IAMB_DEVICE_NAME: &str = "iamb";
8484const IAMB_USER_AGENT: &str = "iamb";
85const REQ_TIMEOUT: Duration = Duration::from_secs(60);
8685
8786fn initial_devname() -> String {
8887 format!("{} on {}", IAMB_DEVICE_NAME, gethostname().to_string_lossy())
@@ -447,20 +446,20 @@ impl ClientWorker {
447446 let (tx, rx) = unbounded_channel();
448447 let account = &settings.profile;
449448
450 // Set up a custom client that only uses HTTP/1.
451 //
452 // During my testing, I kept stumbling across something weird with sync and HTTP/2 that
453 // will need to be revisited in the future.
449 let req_timeout = Duration::from_secs(settings.tunables.request_timeout);
450
451 // Set up the HTTP client.
454452 let http = reqwest::Client::builder()
455453 .user_agent(IAMB_USER_AGENT)
456 .timeout(Duration::from_secs(30))
454 .timeout(req_timeout)
457455 .pool_idle_timeout(Duration::from_secs(60))
458456 .pool_max_idle_per_host(10)
459457 .tcp_keepalive(Duration::from_secs(10))
460 .http1_only()
461458 .build()
462459 .unwrap();
463460
461 let req_config = RequestConfig::new().timeout(req_timeout).retry_timeout(req_timeout);
462
464463 // Set up the Matrix client for the selected profile.
465464 let client = Client::builder()
466465 .http_client(Arc::new(http))
@@ -468,7 +467,7 @@ impl ClientWorker {
468467 .store_config(StoreConfig::default())
469468 .sled_store(settings.matrix_dir.as_path(), None)
470469 .expect("Failed to setup up sled store for Matrix SDK")
471 .request_config(RequestConfig::new().timeout(REQ_TIMEOUT).retry_timeout(REQ_TIMEOUT))
470 .request_config(req_config)
472471 .build()
473472 .await
474473 .expect("Failed to instantiate Matrix client");