Skip to content

Commit a61b2aa

Browse files
authored
Update domain_fronter.rs
1 parent 283073f commit a61b2aa

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/domain_fronter.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ pub struct DomainFronter {
390390
/// h2_fallbacks)` ratio indicates an unhealthy h2 conn or a flaky
391391
/// middlebox eating h2 frames; consider `force_http1: true`.
392392
h2_fallbacks: AtomicU64,
393+
/// We adjust H2OPENTIMEOUT dynamically based on how user's network
394+
/// operates, so that they won't experience things like h1 open timed out after 8s
395+
/// Which would happen because of network's latency & how it operates.
396+
pub h2_open_timeout: AtomicU64,
393397
/// Per-host breakdown of traffic going through this fronter. Keyed by
394398
/// the host of the URL (e.g. "api.x.com"). Read-mostly; only touched
395399
/// on the slow path (once per relayed request), so a plain Mutex is
@@ -614,6 +618,7 @@ impl DomainFronter {
614618
relay_failures: AtomicU64::new(0),
615619
bytes_relayed: AtomicU64::new(0),
616620
h2_calls: AtomicU64::new(0),
621+
h2_open_timeout: AtomicU64::new(8),
617622
h2_fallbacks: AtomicU64::new(0),
618623
per_site: Arc::new(std::sync::Mutex::new(HashMap::new())),
619624
today_calls: AtomicU64::new(0),
@@ -957,11 +962,12 @@ impl DomainFronter {
957962
let tls = self.tls_connector_h1.connect(name, tcp).await?;
958963
Ok::<_, FronterError>(tls)
959964
};
960-
match tokio::time::timeout(Duration::from_secs(H1_OPEN_TIMEOUT_SECS), work).await {
965+
let h2_open_timeout = self.h2_open_timeout.load(Ordering::SeqCst);
966+
match tokio::time::timeout(Duration::from_secs(h2_open_timeout), work).await {
961967
Ok(r) => r,
962968
Err(_) => Err(FronterError::Relay(format!(
963969
"h1 open timed out after {}s",
964-
H1_OPEN_TIMEOUT_SECS
970+
h2_open_timeout
965971
))),
966972
}
967973
}

0 commit comments

Comments
 (0)