Time out every HTTP connection instead of waiting forever
No ureq agent set a timeout, and ureq sets none by default, so a connection dropped silently mid-transfer (a NAT or load-balancer idle drop) hung a JMAP, DAV, EWS or Graph run, or an export, with no error, and the retry logic never got a chance to run. IMAP and ManageSieve already had read timeouts. Every agent now takes its settings from a new net module: 30s to connect, 60s to send the request headers, 5 minutes for the server's first byte, and 30 minutes for a whole response body, which ureq counts as one budget for the body rather than per read: enough for the 512 MiB limit at about 300 KB/s. A JMAP upload's send budget grows with its size, from a 2 minute floor at an assumed 64 KiB/s worst case. A timeout is a transport error, and every client already retries those, so a stalled transfer is now abandoned and retried. Tests pin that down for each client. The TLS setup the seven agents repeated moves to one helper.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
* SPDX-FileCopyrightText: 2026 John Coffey <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*/
|
||||
@@ -10,9 +11,9 @@ use std::time::Duration;
|
||||
use encodify::base64::{Base64, Padding, URL_SAFE};
|
||||
use serde_json::Value;
|
||||
use ureq::config::Config;
|
||||
use ureq::tls::{RootCerts, TlsConfig};
|
||||
|
||||
use crate::exchange_ews::error::EwsError;
|
||||
use crate::net::{tls, with_timeouts};
|
||||
|
||||
pub const SCOPE_APP_ONLY: &str = "https://outlook.office365.com/.default";
|
||||
pub const SCOPE_DELEGATED: &str =
|
||||
@@ -105,18 +106,12 @@ fn device_code_endpoint(tenant: &str) -> String {
|
||||
}
|
||||
|
||||
fn build_agent(allow_invalid_certs: bool) -> ureq::Agent {
|
||||
let config: Config = Config::builder()
|
||||
.http_status_as_error(false)
|
||||
.tls_config(
|
||||
TlsConfig::builder()
|
||||
.unversioned_rustls_crypto_provider(std::sync::Arc::new(
|
||||
rustls::crypto::aws_lc_rs::default_provider(),
|
||||
))
|
||||
.root_certs(RootCerts::PlatformVerifier)
|
||||
.disable_verification(allow_invalid_certs)
|
||||
.build(),
|
||||
)
|
||||
.build();
|
||||
let config: Config = with_timeouts!(
|
||||
Config::builder()
|
||||
.http_status_as_error(false)
|
||||
.tls_config(tls(allow_invalid_certs))
|
||||
)
|
||||
.build();
|
||||
config.new_agent()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user