Add granular timeout configs for sync longpolling.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
use std::{
|
use std::{
|
||||||
cmp::{self},
|
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
collections::{BTreeMap, HashMap, HashSet},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@@ -150,9 +149,15 @@ pub(crate) async fn sync_events_route(
|
|||||||
|
|
||||||
// Hang a few seconds so requests are not spammed
|
// Hang a few seconds so requests are not spammed
|
||||||
// Stop hanging if new info arrives
|
// Stop hanging if new info arrives
|
||||||
let default = Duration::from_secs(30);
|
let timeout_default = services.config.client_sync_timeout_default;
|
||||||
let timeout = body.body.timeout.unwrap_or(default);
|
let timeout_min = services.config.client_sync_timeout_min;
|
||||||
let duration = cmp::min(timeout, default);
|
let timeout_max = services.config.client_sync_timeout_max;
|
||||||
|
let duration = body
|
||||||
|
.body
|
||||||
|
.timeout
|
||||||
|
.unwrap_or_else(|| Duration::from_millis(timeout_default))
|
||||||
|
.clamp(Duration::from_millis(timeout_min), Duration::from_millis(timeout_max));
|
||||||
|
|
||||||
_ = tokio::time::timeout(duration, watcher).await;
|
_ = tokio::time::timeout(duration, watcher).await;
|
||||||
|
|
||||||
// Retry returning data
|
// Retry returning data
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
cmp::{self, Ordering},
|
cmp::Ordering,
|
||||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
@@ -204,8 +204,14 @@ pub(crate) async fn sync_events_v5_route(
|
|||||||
{
|
{
|
||||||
// Hang a few seconds so requests are not spammed
|
// Hang a few seconds so requests are not spammed
|
||||||
// Stop hanging if new info arrives
|
// Stop hanging if new info arrives
|
||||||
let default = Duration::from_secs(30);
|
let timeout_default = services.config.client_sync_timeout_default;
|
||||||
let duration = cmp::min(body.timeout.unwrap_or(default), default);
|
let timeout_min = services.config.client_sync_timeout_min;
|
||||||
|
let timeout_max = services.config.client_sync_timeout_max;
|
||||||
|
let duration = body
|
||||||
|
.timeout
|
||||||
|
.unwrap_or_else(|| Duration::from_millis(timeout_default))
|
||||||
|
.clamp(Duration::from_millis(timeout_min), Duration::from_millis(timeout_max));
|
||||||
|
|
||||||
_ = tokio::time::timeout(duration, watcher).await;
|
_ = tokio::time::timeout(duration, watcher).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -252,6 +252,27 @@ pub struct Config {
|
|||||||
#[serde(default = "default_roomid_spacehierarchy_cache_capacity")]
|
#[serde(default = "default_roomid_spacehierarchy_cache_capacity")]
|
||||||
pub roomid_spacehierarchy_cache_capacity: u32,
|
pub roomid_spacehierarchy_cache_capacity: u32,
|
||||||
|
|
||||||
|
/// Minimum timeout a client can request for long-polling sync. Requests
|
||||||
|
/// will be clamped up to this value if smaller.
|
||||||
|
///
|
||||||
|
/// default: 5000
|
||||||
|
#[serde(default = "default_client_sync_timeout_min")]
|
||||||
|
pub client_sync_timeout_min: u64,
|
||||||
|
|
||||||
|
/// Default timeout for long-polling sync if a client does not request
|
||||||
|
/// another in their query-string.
|
||||||
|
///
|
||||||
|
/// default: 30000
|
||||||
|
#[serde(default = "default_client_sync_timeout_default")]
|
||||||
|
pub client_sync_timeout_default: u64,
|
||||||
|
|
||||||
|
/// Maximum timeout a client can request for long-polling sync. Requests
|
||||||
|
/// will be clamped down to this value if larger.
|
||||||
|
///
|
||||||
|
/// default: 90000
|
||||||
|
#[serde(default = "default_client_sync_timeout_max")]
|
||||||
|
pub client_sync_timeout_max: u64,
|
||||||
|
|
||||||
/// Maximum entries stored in DNS memory-cache. The size of an entry may
|
/// Maximum entries stored in DNS memory-cache. The size of an entry may
|
||||||
/// vary so please take care if raising this value excessively. Only
|
/// vary so please take care if raising this value excessively. Only
|
||||||
/// decrease this when using an external DNS cache. Please note that
|
/// decrease this when using an external DNS cache. Please note that
|
||||||
@@ -2628,3 +2649,9 @@ fn default_ldap_name_attribute() -> String { String::from("givenName") }
|
|||||||
fn default_jwt_algorithm() -> String { "HS256".to_owned() }
|
fn default_jwt_algorithm() -> String { "HS256".to_owned() }
|
||||||
|
|
||||||
fn default_jwt_format() -> String { "HMAC".to_owned() }
|
fn default_jwt_format() -> String { "HMAC".to_owned() }
|
||||||
|
|
||||||
|
fn default_client_sync_timeout_min() -> u64 { 5000 }
|
||||||
|
|
||||||
|
fn default_client_sync_timeout_default() -> u64 { 30000 }
|
||||||
|
|
||||||
|
fn default_client_sync_timeout_max() -> u64 { 90000 }
|
||||||
|
|||||||
@@ -189,6 +189,21 @@
|
|||||||
#
|
#
|
||||||
#roomid_spacehierarchy_cache_capacity = varies by system
|
#roomid_spacehierarchy_cache_capacity = varies by system
|
||||||
|
|
||||||
|
# Minimum timeout a client can request for long-polling sync. Requests
|
||||||
|
# will be clamped up to this value if smaller.
|
||||||
|
#
|
||||||
|
#client_sync_timeout_min = 5000
|
||||||
|
|
||||||
|
# Default timeout for long-polling sync if a client does not request
|
||||||
|
# another in their query-string.
|
||||||
|
#
|
||||||
|
#client_sync_timeout_default = 30000
|
||||||
|
|
||||||
|
# Maximum timeout a client can request for long-polling sync. Requests
|
||||||
|
# will be clamped down to this value if larger.
|
||||||
|
#
|
||||||
|
#client_sync_timeout_max = 90000
|
||||||
|
|
||||||
# Maximum entries stored in DNS memory-cache. The size of an entry may
|
# Maximum entries stored in DNS memory-cache. The size of an entry may
|
||||||
# vary so please take care if raising this value excessively. Only
|
# vary so please take care if raising this value excessively. Only
|
||||||
# decrease this when using an external DNS cache. Please note that
|
# decrease this when using an external DNS cache. Please note that
|
||||||
|
|||||||
Reference in New Issue
Block a user